Problem
I am writing an application for an asp.net 5 console example and I want to use Entity Framework 7 to talk with my backend. I know how to do this in a web application, but I'm lost for how to do this for a console application when not using startup.cs , but main.cs
code
In the web application, you will have the following code in startup.cs :
public void ConfigureServices(IServiceCollection services) { var connection = @"Server=(localdb)\mssqllocaldb;Database=EFGetStarted.AspNet5;Trusted_Connection=True;"; services.AddEntityFramework() .AddSqlServer() .AddDbContext<BloggingContext>(options => options.UseSqlServer(connection)); }
Here you have configured services for entityframework7 and the connection string using SQL Server.
Attempt
I looked through GitHub, Google and Bing, but found only sample projects and code for web applications with EF7. I did not find documentation that discusses EF7 with a console application.
I want to write the above code, but its in my main.cs for my console application. I was not successful, obviously, with the following in main.cs:
SampleConsoleDbContext scab = new SampleConsoleDbContext();
I have no way to tell my program that the connection string is, and I still doubt that this is the correct way to get the context created in main.cs
I would be grateful for any help, advice or comments regarding this interesting issue. Thanks.
source share