entity framework 4 - asp.net MVC 4 EntityType: EntitySet has no keys defined -
i mvc newbie go easy on me please.
i getting 2 errors when seek add together migration. follows:
entitytype 'icon' has no key defined. define key entitytype.
entitytype: entityset 'icons' based on type 'icon' has no keys defined.
i including icon within model, so:
public class icon { public string iconname { get; set; } public string iconcolor { get; set; } public int backgroundxpos { get; set; } public int backgroundypos { get; set; } public string iconcolorhover { get; set; } public int backgroundhoverxpos { get; set; } public int backgroundhoverypos { get; set; } } public class gallerythumbnail : cssboxmodel { [displayname("thumbnail image outline color")] public string thumbnailimageoutlinecolor { get; set; } [displayname("thumbnail menu font")] public cssfont thumbnailmenufont { get; set; } [displayname("thumbnail icon color")] public icon thumbnailiconcolor { get; set; } } how address class below different working:
public class address { public string adress1 { get; set; } public string adress2 { get; set; } public string adress3 { get; set; } public string city { get; set; } public string county { get; set; } public string state { get; set; } public string zip { get; set; } public string country { get; set; } } [table("userprofile")] //could pp empolyee, subscriber or subscriber's client public class userprofile { [key] [databasegeneratedattribute(databasegeneratedoption.identity)] public int userid { get; set; } public string username { get; set; } public bool? gender { get; set; } public address address { get; set; } //billing address public address shipaddress { get; set; } } i did not add together key in either icon or address class because have no intention of storing specific info in db. simply used within other classes. wy 1 neededing id , other not?
i have not created public dbset icons { get; set; } in db context either.
also can tell me called when utilize class within ( or instance of class within class in these examples ) ?
much appreciated!
since address entity has no key defined entity framework assumes it's complex property, , userprofile table rendered columns named addres_address1, address_address2, address_address3, address_city, , on...
even though haven't declared entityseticons dbset on context class, it's still beingness added implicitly because 1 of other classes somewhere has icollection or ienumerable property defined.
more info on code conventions here: http://msdn.microsoft.com/en-us/data/jj679962.aspx
so, either decorate collections notmapped @kamyar said or remove references class declared dbset.
asp.net-mvc entity-framework-4
No comments:
Post a Comment