Monday, 15 September 2014

c# - How to best map a string array from a legacy database to EF5 property? -



c# - How to best map a string array from a legacy database to EF5 property? -

we need map string column database, used array of values, list of business entities in entity framework 5.

in database info stored string of length 12, each character in string defines whether enabled/disabled. value of 0 character means item disabled, value of 1 character means enabled.

for illustration if first , sec items enabled , rest disabled value in db 110000000000.

in business entities want these configurations represented list manipulation , binding presentation layer easier, ideally represented list of objects containing index value , boolean define whether active or not.

normalizing database sadly not option, in active utilize other applications.

we perhaps create view in database , map that, or additional property in entity marked "not mapped database" create transformation each has limitations.

and of course of study happens in more 1 place if can define pattern case can reuse way throughout project , save hair.

any suggestions on way accomplish this?

you should able accomplish fluent api

something imagining needing.

[complextype] public class magicstring { public string key { get; set; } public <ilist> yourmagicallist { get; set; } } public class context : dbcontext { public dbset<someconfigurationobject> configurationobjects { get; set; } protected override void onmodelcreating(dbmodelbuilder modelbuilder) { modelbuilder.entity<someconfigurationobject>().property(u => u.magicstring.key) .hascolumnname(""yourcolumn"); } }

c# asp.net-mvc entity-framework

No comments:

Post a Comment