c# - Non-Entity Class Requiring [Key] Attribute -
i getting entitytype 'schedulenote' has no key defined. define key entitytype.
poco has nothing entity framework. ef require define [key] every class in project whether or not deals database?
update:
here schedulenote code:
using system; namespace domain { public class schedulenote { public string noteid { get; set; } public notetypeenum type { get; set; } public string typefk { get; set; } public string userid { get; set; } public string authorname { get; set; } public string subject { get; set; } public string message { get; set; } public datetime? startdate { get; set; } public datetime? enddate { get; set; } public datetime insertdate { get; set; } public datetime? deletedate { get; set; } public bool ispublic { get; set; } public bool ismodified { get; set; } public bool isdeleted { get; set; } } public enum notetypeenum { insight_event = 0, insight_series = 1, insight_team = 2 } }
so when application starts (asp.net web api), first call database using ef (which not related class) errors "no key defined" error. class not defined in dbcontext or anywhere. exists in project , ef not doesn't have [key] attribute.
i add attribute , move on not explain "why" need so. understanding new or legacy code not have altered introduction of ef.
since use class related entity in way, you'll need use [notmapped]
attribute on property let ef know don't want auto-wireup property. or remove reference.