Difference between .edmx file and creating an Entities.cs file
I have looked at two of Microsoft's tutorials for MVC. In one tutorial they are creating a .edmx file to handle the Entity Framework in order to execute Linq queries. In another tutorial they made a class called "MusicStoreEntities.cs" here is the code:
using System.Data.Entity;
namespace MvcMusicStore.Models
{
public class开发者_运维知识库 MusicStoreEntities : DbContext
{
public DbSet<Album> Albums { get; set; }
public DbSet<Genre> Genres { get; set; }
public DbSet<Artist> Artists { get; set; }
public DbSet<Cart> Carts { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderDetail> OrderDetails { get; set; }
}
}
And the tutorial creates an instance of this class and starts doing Linq queries as well. What are the differences between these 2 methods? and how can I make DbSet objects in a .edmx file? Thank you.
There are various ways to create your model structure.
- You can code POCO classes first, and create the database manually.
- You can code POCO classes first, and create the database automatically using code first libraries.
- You can create your database schema, and import it into a class diagram (which will supply all the models and navigation).
- You can create your class diagram, and create your database schema from that.
1 and 2 create only the cs, while 3 and 4 create the edmx.
You can check this for Code First EF (this includes the DbSet part of your question).
EDIT: You can even use POCO classes with an existing database, as posted here.
精彩评论