简体   繁体   中英

Visual Studio 2015 project that references both EF 5 and EF 6 projects

Can anybody tell me if there is a way to have a project that references both Entity Frameworks 5.x and 6.x? I have two separate data projects and one has to be EF 5.x, it's Actian Pervasive and they don't support EF 6.x. The other is a MS SQL Server done in EF 6.x. I'm needing to use both of these in another project to talk to both databases. I'm thinking I'm just SOL but thought I'd see if anybody has any suggestions.

I don't think you can use two versions of the same library in the same project, but there are other workarounds. You can create 2 webapis, one pointing to your 5.x project, exposing the methods you want, and another one pointing to your 6.x project, doing the same exposure.

After that, on each webapi, you can create Api Clients in a contract like layer, and expose that to your clients via nuget.

to create clients that post to your webapi, check this post . From there, you cant create a client with something like this:

public class MyApiClient : BaseHttpClient, IMyApiClient
{
    public MyApiClient() : base(ConfigurationManager.AppSettings["WebApiUrl"])
    {
    }

    public ReturnDTO<ResponseDTO> MyMethod(FilterDTO filter)
    {
        return this.ExecutePost<FilterDTO, ReturnDTO<ResponseDTO>>("YourWebApiURL", filter);
    }

}

the BaseHttpClient class is just a class to abstract the implementation of the WebClient.

After doing that, you can expose this contract layer to your clients, via nuget, and they can simply do:

var client = new MyApiClient();
var response = client.MyMethod(new FilterDTO());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM