开发者

Extending Core Edmx, multiple Edmx's in EF4

开发者 https://www.devze.com 2023-01-30 09:14 出处:网络
We have an EF4 EDMX which contains ~300 entities which are used in our core product suite (entities imported from database).

We have an EF4 EDMX which contains ~300 entities which are used in our core product suite (entities imported from database).

When we get new clients, more often than not they want to store extra information and have us develop custom processes which is outside of our business domain and completely custom. E.g. We got a contract with a security company and they wanted to store information about their security levels and have processes that act on these levels.

In every case we need to add custom tables AND/OR add custom fields to existing entities. We had a good way of doing this with previous tech in which the core class libraries were not junked with custom tables etc. We simply inherited from the core entity (equivilent to EntityObject in EF) in a custom class library and added customisations as required.

Similarly we don’t want to add these custom tables and attributes to our core EDMX. We want to essentially “Inherit” from the core EDMX in a new custom EDMX in a seperate class library where we can add the customisations. The inheritance will allow us开发者_C百科 to do everything we can in Core EDMX plus a bit more.

We are using a t4 template to generate our repositories based on this blog post (We are not using model-first approach):

http://geekswithblogs.net/danemorgridge/archive/2010/06/28/entity-framework-repository-amp-unit-of-work-t4-template-on.aspx

Can we extend an EDMX like we require?

We came up with one hackish solution, a method extension on core entities which returns a custom entity in seperate EDMX as in below:

  public static class CoreEntityExtensions
  {
    public static EntityConnection EntityConnection;

    public static CustomUserEntity CustomUserDetails(this User coreUser)
    {
      ICustomUserEntityRepository customUserRepository = new CustomUserEntityRepository(EntityConnection);
      return customUserRepository.All().SingleOrDefault(u => u.id == coreUser.id);
    }
  }

This isn't ideal though for a few obvious reasons.

Any help is much appreciated.


Doesn't help you much I think, but NHibernate can do that pretty easily. We have the same scenario as you and NH allows us to model across DLL's without any trouble.

Sorry, not really an answer but just advice to consider the alternatives for anyone else reading this.

0

精彩评论

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