orm - Mapping value-type collection in Entity Framework -
similar question: mapping collection of strings entity framework or linq sql
i have role class:
public class role { public int roleid { get; set; } public virtual ilist<string> actions { get; set; } }
i have mapping table in db, "roleactionmapping" columns, "roleid" , "action". "roleid" foreign key point role table, , "action" varchar. cannot seem setup ef mapping populate role class roleactions.
any ideas on how achieve this? thanks!
ef doesn't offer such mapping.
if want map must use:
public class role { public int roleid { get; set;} public virtual ilist<roleaction> actions { get; set; } // should initialize collection } public class roleaction { public int actionid { get; set; } // pk must defined or entity readonly public string action { get; set; } public virtual role { get; set; } }
you can further extend role
class provied not mapped property returning ienumerable<string>
internally select data actions
property.
but once follow approach should consider model m:n relation between role
, action
entity.
Comments
Post a Comment