.net - ShortGuid with Entity Framework -
i installed shortguid nuget , use key table. store 22-char string in database rather guid, it's easier find records when debugging. how entity framework create column?
i tried adding:
public shortguid newcol { get; set; }
but no column added. tried:
[column(typename = "nvarchar")] [maxlength(22), minlength(22), stringlength(22)] public shortguid newcol { get; set; }
but still no column. presumably ef doesn't understand i'm trying ignores column? works fine if use guid:
public guid newcol { get; set; }
i suppose use 22-char string column, ideally i'd use shortguid type. possible?
i have experienced similar entity framework in past. far understand, type of column cannot complex type. limitation of entity framework (but not 100% sure this).
i share in these sort of situations, though aware answer more of workaround proper answer question.
i create 2 properties in class: 1) property acting column in database , 2) property intended keep in class. following code snippet explain trying do.
event.cs:
namespace mycontext.model { public partial class event { [key] public int eventid { get; set; } public string accesstokenstr { get; set; } // [notmapped] tells entity framework not make column following property [notmapped] public shortguid accesstoken { { return new shortguid(accesstokenstr); } set { accesstokenstr = value.tostring(); } } } }
hope helps.
Comments
Post a Comment