Created
February 9, 2017 09:41
-
-
Save shammelburg/4060bcf3049dc15057e294cf4bc406f9 to your computer and use it in GitHub Desktop.
A partial class for connecting to ASP.NET Core with full .NET framework from a Class Library using ADO.NET Entity Data Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Data.Common; | |
using System.Data.Entity.Core.EntityClient; | |
namespace DataAccessLayer.Models | |
{ | |
public partial class MyEntities | |
{ | |
public MyEntities(string connString) | |
: base(GetSqlConnection(connString), true) | |
{ | |
} | |
public static DbConnection GetSqlConnection(string connString) | |
{ | |
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder(connString); | |
return new EntityConnection(entityBuilder.ToString()); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
// Add framework services. | |
services.AddMvc(); | |
services.AddScoped(p => | |
{ | |
return new MyEntities(Configuration["ConnectionStrings:MyEntities"]); | |
}); | |
services.AddScoped<IDataModel, DataModelRepository>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment