c# - Persisting an object using Entity Framework 6.1.2 that includes an interface -
i having difficulty persisting objects sql server db using entity framework. trying following using code first methodology:
public class objecta { public string name { get; set; } public imyinterface interfaceobject { get; set; } public objectd anotherobject { get; set; } } public interface imyinterface { } public class objectb : imyinterface { public string somepropertyb { get; set; } } public class objectc : imyinterface { public string somepropertyc { get; set; } } public class objectd { public string somepropertyd { get; set; } } my application context class contains following:
public dbset<objecta> objecta { get; set; } public dbset<objectb> objectb { get; set; } public dbset<objectc> objectc { get; set; } public dbset<objectd> objectd { get; set; } after updating database, contains tables each of above entities. when attempt save objecta using context.savechanges(), data objecta , objectd persisted, objectb or objectc behind interfaceobject not persisted.
is attempting possible? if not, have ideas on other ways persist objecta can have 1 instance of either objectb or objectc, not both?
i solved problem making interface abstract class id field:
public interface imyinterface { [key] public int id { get; set; } } now in database, using table per hierarchy represent classes in question.
Comments
Post a Comment