c# - Entity Framework: Saving a record with FK values and NOT looking up relationships -


I have a table "expense" in which an "expense type type" table contains the FK value. Right now, if I want to save a new expense, then I must get the int value of the firstfac, one lookup for the exponent table, and the object must be given an object object. For example:

  // create new expense var e = new spend (); // See related expenditure types var and = context.ExpenseTypeSet.First (e -> e.expenseTypeID == 10); // set field value e.expenseName = "some name"; E.expenseType = At; // save context.Save ();  

Is there a way to create / insert records without complying to look at FK tables? Requires lookup and hits additional database forces. I already know the FK ID ... so is there a way to just set the ID and allow it to be happy?

Thank you in advance -

You can also use EntityReference: < / P>

  e.expenseTypeReference.EntityKey = New EntityKey ("MyContainer.expenseTypeSet", "Expedicepad", 10);  

I have included this and related issues:

What you especially want to see is the fake property for the FK Talks about making You do not need to go to it, unless you want it, but principles are useful.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -