I have two tables, Transaction
and TransactionLineItem
that are related through a 1:n relationship (TransactionLineItem
has a TransactionKey
field that points to the Transaction
). I've created the Transaction
and exactly 1 TransactionLineItem
and posted them to the database.
Transaction tran = new Transaction();
context.Transactions.InsertOnSubmit(tran);
context.SubmitChanges();
TransactionLineItem tli = new TransactionLineItem();
tran.TransactionLineItems.Add(tli);
context.SubmitChanges();
Later when I access the TransactionLineItem from the same Transaction object it takes an unreasonable amount of time. On my development system it takes about 1.6 seconds but on my production system (a single board computer with a 1gHz processor and a gig of RAM) it can take as long as 5 seconds.
List<TransactionLineItem> lineItems = tran.TransactioinLineItems.ToList();
I've tried several different ways of accessing the item. I've used the LoadWith
function on the data context and I've called TransactionLineItems.Load()
but all that seems to do is move the lag time around. I've even called the Load() function immediately after the first SubmitChanges()
but even with the collection guaranteed to be empty the lag time is still present.
I've used the SQL server profiler to pull out the query and try running it directly in the Management Studio but the query runs there in under a second. Also at the moment I'm running this against a mostly empty database.
Either I need to find a way to make the Load()
call run faster, or I need a way to bypass the load completely but only in specific cases.
Thanks.