It is okay to have multiple context in a C# ASP.NET program?
I am on a big project that use WebForms and i wish t开发者_如何学Goo use LINQ TO SQL but because its gonna get slow in VS if i add everything to that model (furthermore i still use standard SQL) it is okay to multiple contexts ?
EDIT: What i was saying is.. i have almost 100 tables in the database and i cant add them all in one context since i am still using raw sql a lots.. so i though i could seperate the whole thing and create many contexts based on operations. So if i have to add evaluation forms then the context will interact with all the table related to evaluation forms.
THanks.
If you have logical separation in db schema, it will make sense to have multiple contexts. Also L2S do not prevent you from using raw sql, even more, you can use context's connection and utilize it's methods to execute sql queries. Also you can map SPs with L2S
The other caveat of having multiple contexts is that you will not be able easily pass objects between contexts. In your case I would prefer to use EF with POCO (probably even new arrived code first approach ), using it you'll be able to pass objects from one context to another, otherwise you'd need to use some kind of Object-to-Object mapping
UPD: that is how you can use LINQ2SQL with raw sql:
db.ExecuteQuery<Customer>("select * from dbo.Customers where City = {0}", "London");
db.ExecuteCommand("UPDATE Products SET QuantityPerUnit = {0} WHERE ProductID = {1}", "24 boxes", 5);
read this article DataContext.ExecuteCommand Method
I'm not sure what you're asking, but generally, you don't need more than one context.
精彩评论