开发者

EntityFramework or LinqToSql Entity Namespace

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 t开发者_Go百科hat we only can specifiy a unique "Entity namespace" like Infrastructure.SqlServer.Entities

Thanks.


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


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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜