anthonypliu
anthonypliu

Reputation: 12437

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.

Upvotes: 1

Views: 3501

Answers (1)

Kenji Kina
Kenji Kina

Reputation: 2412

There are various ways to create your model structure.

  1. You can code POCO classes first, and create the database manually.
  2. You can code POCO classes first, and create the database automatically using code first libraries.
  3. You can create your database schema, and import it into a class diagram (which will supply all the models and navigation).
  4. 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.

Upvotes: 3

Related Questions