http://diwakarko.blogspot.com (दिवाकरको ब्लग)

Using Entity Framework

No comments
Model

    [Bind(Exclude="GenreId")]
    public class Genre
    {
        [ScaffoldColumn(false)]
        public int GenreId { get; set; }
        public string GenreName { get; set; }
        public string Description { get; set; }
        public Boolean Status { get; set; }
             
    }



Entity Class

    public class MVCBookStoreEntities:DbContext
    {
        public MVCBookStoreEntities()
            : base("name=ApplicationServices")
        { }
        public DbSet genres { get; set; }
    }

Global.asax

on Application_Start add this
       
    Database.SetInitializer(new DropCreateDatabaseIfModelChanges());


Controller


MVCBookStoreEntities db = new MVCBookStoreEntities();

        public ActionResult Index()
        {
            List gen =new List();
            gen=db.genres.ToList();
            var model=from g in gen
                      orderby g.GenreId descending
                      where g.Status==true
                      select g;
            return View(model);
        }

No comments :

Post a Comment