开发者

Stop linq from caching tables

when a new entity in开发者_开发百科 my database is created and then i request a table from the datacontext the new entity does not appear. is linq caching the table and returning the cached version? if so how do i stop linq from doing this.

DALConnector.Dc.Order.InsertOnSubmit(NewOrder);
DALConnector.Dc.SubmitChanges();

now i click a button that shows a form with a gridview on it databound to DALConnector.Dc.Order which doesn't show the new order


How are you rebinding the grid? It does not cache the result, so I am not sure why that is an issue. You have to requery the context to get the new record... Or, if you are rebinding an object's records (like you are binding customers), you could get away with ensurihg the order is added to the Orders collection in the customer object, and not having to requery.

So if you are binding in this way:

grid.DataSource = customer.Orders;

You would only get the new order back if you did:

customer.Orders.Add(newOrder);
dc.Orders.InsertOnSubmit(newOrder);
dc.SubmitChanges();

And then, you could bind customer.Orders directly.


The Linq2Sql DataContext does not cache the complete Table, it only has a cache of the retrieved entities for change tracking purposes. If you would use a new DataContext for querying after you have inserted the order, your result will probably be the same.

AS you are using Linq2Sql, which can only be used with SQL Server, I recommend firing up the SQL Server Profiler and check if a real insert statement is submitted to the database in the first place.

Check your dbml, are you using runtime insert or a stored procedure for Order?

Also check if you're not swallowing any Exceptions the DataContext may raise on SubmitChanges().

If this does not help, please add your query code so we can verify it also.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜