开发者

Reuse entities in Entity framework accross multiple Visual studio solutions - common columns and differing columns - database, model or code first?

开发者 https://www.devze.com 2023-03-24 11:58 出处:网络
I require assistance on choosing a CRUD method for the requirement of separate tables with both common and varying fields for multiple enterprise solutions.

I require assistance on choosing a CRUD method for the requirement of separate tables with both common and varying fields for multiple enterprise solutions.

Here is an simplified example of columns in a table called Organization in each solution database.

Db1: Id (common) Name (common) Address (common) ClientStatus

Db2: Id Name Address NoOfEmployees RegistrationStatus

Db3: Id Name Address SecondaryAddress

Db4: Id Name Address LinkedId

Background:

I have clients in the same industry and all have similar MIS (frontend with database) systems I develop. Functional concept for all clients are the same but 30% table's table columns differ, business rules differ and screens must match each unique clients requirement.

Each client's system has its own Visual studio solution and own SQL server database. Clients own their specific database and source code.

All clients require functionality changes regularly. Sometimes new data columns to a table get added for all clients due to government/financial requiremen开发者_运维百科t/value add and sometimes only added for one specific client where it is unique request to that client.

Looking at the database structure between clients' databases the tables have the same table names. Tables have 70% the same table columns except with the difference being when added columns or new tables are added for a client that is unique to that client. Front end screens vary as well.

Now to create a new solution and maintain the solutions is is time consuming due to being difficult to differentiate between core and custom code due to no code separation between core fields,rules & views and unique fields, rules & views.

Design:

  1. I need to share common CRUD and business rules between solutions
  2. I need to keep a separate solution per client and one client's unique solution code or table fields must not be in another client's solution code and database.
  3. I don't need a separate table linking to each common table or columns called custom1,custom2,custom3 as clients have their own reporting tools on the database that need english column names in the same table.
  4. The CRUD must work with MVC3 Razor as well as Silverlight 4 frontend, sql server 2008R2 backend.
  5. Adding new db fields afterwards must be easy to do and not have a big impact.

My plan:

I had an idea to redesign the system using base classes for the common tables names e.g table OrganizationBase and then have a class that inherits from it e.g. OrganizationExtend contains the unique column names The CRUD would then concatenate the fields of the base class and parent class together and update the database using ADO.net. The base classes source code would be a shared between solutions.

However I would like to use entity framework for my goals but I am unsure if this is possible using EF or if EF supports my goal of separating common fields with uniquecolumns per db table and how to go about designing it. I have not used EF before but would like to for RAD.

My question:

Is my requirement possible with Entity framework and if so how or is a another CRUD solution more ideal for this requirement?

From what I have read up about entity framework it is not clear if code, model or database first will best meet my requirement? Advice would be appreciated.


Database first and model first use edmx files that won't suit inheritance.

With EFcode first you can use normal C# OO classes with inheritance and use EF mapping to map the inherited class to the table.

So my code would look like:

Shared namespace classes between solutions:

public abstract class OrganisationBase
{
    public int OrganisationId { get; set; }
    [Required]
    public string Name { get; set; }
    [Required]
    public string Address { get; set; }
    [Required]
    public string TelNo { get; set; }
}

Client 1 specific namespace classes:

public class Organisation : OrganisationBase
    {
        [Required]
        public int ClientStatusId { get; set; }
    }

Client 2 specific namespace classes:

public class Organisation : OrganisationBase
{
    [Required]
    public int NoOfEmployees { get; set; }
    [Required]
    public int RegistrationStatusId { get; set; }
}
0

精彩评论

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