asp.net - Using Entity Framework with no defined keys -
i having problems keys when trying make controllers, reading of questions posted in here, , found needed explicitly define key in variable, , did so.. problem still persist , don't know how fix it.
error this:
"entity type 'product' has no key defined, entityset 'products' has no keys defined"
code:
using system; using system.collections.generic; using system.componentmodel.dataannotations; using system.componentmodel.dataannotations.schema; using system.data.entity; using system.linq; using system.web; namespace mvc_catalogo.models { public class product { private string descripcion { get; set; } private string barras { get; set; } private string alterno { get; set; } private double precioc { get; set; } private double preciop { get; set; } private string imagen { get; set; } [key] private guid productoid { get; set; } private guid idproveedor { get; set; } private int activo { get; set; } public class jomdbcontext : dbcontext { public dbset<product> products { get; set; } } } }
answer:
i'm not sure if of these issue, might try: 1. making properties public instead of private. 2. matching class name id field. change productoid productid. 3. annotating id field [databasegenerated(databasegeneratedoption.identity] [key]
Comments
Post a Comment