views:

67

answers:

3

Hi,

I want to specify entity namespace based on my domain structure. Usually like that :

Infrastructure.SqlServer

  • Customers (NS : Infrastructure.SqlServer.Customers)
    • Customer
    • Address
  • Products (NS : Infrastructure.SqlServer.Products)
    • Product
    • ProductVariant
    • ProductCategory

How can i do that with LinqToSql or EntityFramework ? It seems that we only can specifiy a unique "Entity namespace" like Infrastructure.SqlServer.Entities

Thanks.

A: 

I've done this in our application. Our entity namespaces are based on our SQL Server schemas. Each namespace is in it's own DBML. Unfortunately, L2S cannot model relationships across .DBML files, but we've worked around this to some extent.

Randy

Randy Minder
+1  A: 

This is possible with the EF, but I wouldn't recommend it.

The problem is you have to go into the EDMX and manually edit the XML (i.e. leave the designer) to create multiple schemas inside the CSDL portion of the EDMX file.

Definitely not worth the hassle in my opinion.

Alex

Alex James
A: 

Well you can create separate models over your database schema by eliminating the tables in each you don’t require. You can do this with either L2S or the Entity Framework. I'm guessing that’s not what you mean however. You would not be able to include entities from both models in a query.

What you Probably Want...

Most people what to do this for maintenance reasons; i.e. split the model into modular chunks. I've experimented quite a lot with this myself. There is an article here if your determined to persevere. Editing the verbose EDMX file manually is currently very clumsy and error prone. If what your asking is the total extent of your desired split thats probably fine. If you've a larger schema with more splits you'll probably find it too painful.

This is clearly desirable functionality for many, and required for use against a typical Enterprise database. In the long run this will probably be fixed but for now my advice would be to work around the issue. To be complete LinqToSQL does not support splitting a model in any fashion.

Royd Brayshay