System.Data.Entity.ModelConfiguration.ModelValidationException' occurred in EntityFramework.dll in c# consol application -
i new in entityframework , start code, not know why got exception handler "system.data.entity.modelconfiguration.modelvalidationexception' occurred in entityframework.dll" in line var count = context.albums.count();
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.data.entity; namespace entityframework1 { class program { static void main(string[] args) { using (var context = new musicalbumcontext()) { var count = context.albums.count(); console.writeline(count); context.albums.add(new album() { name = "best", cost = 34.43m }); context.savechanges(); console.writeline(count); console.read(); } } } public class musicalbumcontext:dbcontext { public dbset<album> albums { get; set; } } public class album { public string name { get; set; } public decimal cost { get; set; } }
}
you need following process
class program { static void main(string[] args) { using (var context = new musicalbumcontext()) { var count = context.albums.count(); console.writeline(count); context.albums.add(new album() { name = "best", cost = 34.43m }); context.savechanges(); console.writeline(count); console.read(); } }
}
public class musicalbumcontext:dbcontext { public musicalbumcontext() : base("connectionstring") { } static musicalbumcontext() { database.setinitializer(new dropcreatedatabaseifmodelchanges<musicalbumcontext>()); } public dbset<album> albums { get; set; } } public class album { public string name { get; set; } public decimal cost { get; set; }
}
after run following commnads enable-migrations contextname add-migration initialcreate update-database -verbose -fource
Comments
Post a Comment