I have an Expenses table that contains the FK value in the ExpenseType table. Right now, if I want to save a new expense, I first get the value int FK, look at the ExpenseType table and assign the object to the expense object. For example:
var e = new Expense();
var et = context.ExpenseTypeSet.First(e -> e.expenseTypeID == 10);
e.expenseName = "Some name";
e.expenseType = et;
context.Save();
Is there a way to create / insert a record without first requesting to the FK table? The search is unnecessary and causes extra database hits. I already know the FK ID ... so is there a way to just set the identifier and let it be happy?
Thanks in advance -
source
share