I'm currently developing an ASP.NET 5 Web-API application with VS2015 Ultimate Preview. Some things have changed about configuring EF7 on this new platform.
I've already checked the help in this page: https://github.com/aspnet/EntityFramework/wiki but it doesn't show all the step needed to successfully complete a connection with EF7 (it shows only a partial answer)
Can anyone bring a step-by-step tutorial on how would be the correct way to connect to a database (SQL Server) using EF7?. (not using old syntax like in MusicStore sample app but using more recent syntax)
The code should be the same as you linked in the sample app. You register the context in Startup.cs, within ConfigureServices method using the following code:
public void ConfigureServices(IServiceCollection services)
{
// Add EF services to the services container.
services
.AddEntityFramework(Configuration)
.AddSqlServer()
.AddDbContext<MyDbContext>(options =>
{
options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString"));
});
}
Then your MyDbContext will be available for dependency injection, and in your controllers you can do
public MyController(MyDbContext context)
{
...
}
That's it
The following tutorials helped me :
Introduction to Web API : Part 2 – Integrating with Entity Framework 5 Code First
Generic Repository Pattern with Entity Framework and Web API
Building an ASP.NET MVC4 Application with EF and WebAPI
Entity Framework Code First and ASP.NET Web API
Getting started with ASP.NET 5 MVC 6 Web API & Entity Framework 7
Stephen Walther has an updated Music Store tutorial. It starts here
Related
I have a ASP.NET Core MVC Application that uses EntityFramework Core and Identity.
So far I have only 2 Connection Strings in Appsettings.json .
Context for Models and Context for Identity.
I would like to have a Database Connection string for each user group.
Does anybody have experience with Orchard Core Framework? It was linked on the Microsoft Documentation, because multi Tenant Database for each User is not supported by Identity.
Can anybody tell me if it is difficult to migrate an existing Project to this Framework?
I also read about Multi Tanent App on a blog form Gunnar Pipemann. This approach would be an alternative for me.
Maybe some of you have developed a similiar App with Asp.net Core MVC and can share their approach.
I am starting to work on a new project so working on laying on the architechture at this moment.
So basically we want to keep a service oriented architecture using MVC web api.
So I had the following structure in mind:
Project.Core (All Poco classes)
Proect.Data (All entity framerwork)
Project.Service (All Web API ??)
Project.Web
We would be working for the first time on webapi here. So wanted to know how do we intergrate webapi here.
Most of the articles we saw read had created a mvc web application and had selected webapi in that. But we
were looking to create separate service layer just for webapi. Is this the correct practice to do that or
I am missing something here.
We basically wanted not to have a tight coupling b.w MVC web and web api here. If we create web api as part
of mvc then how can we separately access our web api.
WOuld appreciate inputs.
I normally use the project template provided by Visual Studio. Choose Empty ASP.NET project template and then select Add folders and references for Web API. It will create the folder structure needed/recommended purely for a Web API project without any MVC reference. I generally create a separate project for Data Access and use that from the Web API project.
I have been checking resources to implement authentication in my web forms application built with entity framework. All examples I found are MVC-related. I have used regular Asp.Net Membership framework a long time before I began to use EF. However, I could not find Membership implementation with Entity Framework code-first. I did implement the Claims-Based Identity (EF created the tables for me in DB) but I do not know how to utilize it in the application (like login), and it looks more complicated to me. Can anyone guide me ?
There are a couple of good tutorials on the asp.net web site:
http://www.asp.net/identity/overview/getting-started/adding-aspnet-identity-to-an-empty-or-existing-web-forms-project
http://www.asp.net/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/membership-and-administration
I got some information for upgrading MVC 4 and Web API to MVC 5 and Web API 2
http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2
I followed the steps from that hyperlink.
For upgrading from Web API to Web API 2, in global.asax, change:
WebApiConfig.Register(GlobalConfiguration.Configuration);
to
GlobalConfiguration.Configure(WebApiConfig.Register);
I am unable to find Configure() under GlobalConfiguration. Am I missing any reference here or am I supposed to include any definition or namespace?
if you have :
using System.Web.Http;
at the top of your file, then check if your project is actually referencing MVC 5 / Web API 2 assemblies
I need to write an extensible ASP.NET MVC 3 application, while an extension is a .dll with a very specific purpose (i.e: a forum extension, a blog extension, a wiki extension, etc).
An extension wouldn't have any views though, which should make this process much simpler. It should only has controllers and a few models.
I've been thinking about implementing this with MVC areas, and load them like so:
// Global.asax
public static void PreApplicationStartMethod()
{
foreach (var file in Directory.GetFiles(
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Extensions/"), "*.dll"))
{
BuildManager.AddReferencedAssembly(Assembly.LoadFile(file));
}
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
...
}
Now this worked perfectly, but still, it seems like a pretty old and static way... .NET 4 has Managed Extensibility Framework. MVC 3 has Dependency Injection.
I've read about Portable Areas and SharpArchitecture. I was trying to understand the Orchard plugin framework both from the source code and the documentation. But still I'm not sure what should I use.
To make my question more practical - how would you include Controllers and Models from an external project to the main MVC web application? What is the best way to do this? Should I use Dependency Injection here?
Thanks.
I've had a look at this previously, let me know if these help:
Modular ASP.NET MVC using the Managed Extensibility Framework (MEF), Part One
Modular ASP.NET MVC using the Managed Extensibility Framework (MEF), Part Two
Modular ASP.NET MVC using the Managed Extensibility Framework (MEF), Part Three
MVC3 and MEF