views:

110

answers:

3

I have a SQL Server 2008 database with > 300 tables. The application I have to design is an Windows Forms app, .NET 3.5, C#.

Which is the best way to work with Linq-to-SQL ?

I intend to make a datacontext for each business entity.

Is there any problem ?

I need to know if this way of working with Linq-to-SQL has any disadvantage or can create performance issues ?

Thanks.

+5  A: 

There is no point in making a data context for each business entity, you only need one datacontext per database.

Ben Robinson
A: 

Hi, well it depends on how many users will use your database simultaneously not how many tables are there. So its all about typical database issues: number of connections, locking and other stuff.

Voice
I don't think he is talking about instantiating a `DataContext`, but defining a DBML file per entity.
Steven
Yes, defining a DMBL file per entity. Thanks.
sh00
+3  A: 

You should typically have 1 single DBML file (=data context) per database. You should certainly not create a DataContext per business entity, because doing this would make you lose most of the useful capabilities of LINQ to SQL, like memory transactions (unit of work), lazy loading, and doing LINQ queries over multiple entities.

You have a pretty big model (+300 tables) which means a lot of entities. A lot of entities is not a big problem, except for the LINQ to SQL designer. Using the designer with such big models can be pretty annoying. This can be a reason to split a domain in multiple sub domains (with each a DBML file), but certainly not one per entity. However, keep in mind that you loose the L2S capabilities at the boundaries of the domains.

In the past I advised a team, who had split up their +150 entities domain in 5 DBML files, to merge them back together to a single DBML. The pain of editing the model went up, but the pain of using multiple DataContexts went away, which lowered the overall pain drastically for them.

Steven
Thanks.Please, what exactly do you mean by "The pain of editing the model" ?I think that splitting a big datamodel in sub domains can solve some performance problems.Do you have experience in working with big datamodel/single DBML file in win forms/SQL Server database that requires 100+ concurrent users ?Thanks.
sh00
The number of data context classes you create will have no effect whatever on performance.
Ben Robinson
I agree with Ben. I can't imagine having multiple DBML's have any impact on performance. Please explain why you think that.
Steven