c# - Entity Framework 6 Code First - Custom Type Mapping -


i'm using models inside domain not serialization- or mapping-friendly, such structs or classes system.net.* namespace.

now i'm wondering if it's possible define custom type mappings in entity framework.

pseudo:

public class physicaladdressmap : complextype<physicaladdress>() {     public physicaladdressmap() {          this.map(x => new { x.tostring(":") });         this.from(x => physicaladdress.parse(x));     } } 

desired result:

someentityid       someprop         physicaladdress    someprop ------------------------------------------------------------------            4          blubb       00:00:00:c0:ff:ee        blah                                             ^                                            |                              // physicaladdress got mapped "string"                              // , retrieved                              // physicaladdress.parse(string value) 

wrap notmapped property of type physicaladdress mapped string property handles conversions:

    [column("physicaladdress")]     [maxlength(17)]     public string physicaladdressstring     {                 {             return physicaladdress.tostring();         }         set         {             physicaladdress = system.net.networkinformation.physicaladdress.parse( value );         }     }      [notmapped]     public system.net.networkinformation.physicaladdress physicaladdress     {         get;         set;     } 

update: example code comment asking wrapping functionality in class

[complextype] public class wrappedphysicaladdress {     [maxlength( 17 )]     public string physicaladdressstring     {                 {             return physicaladdress == null ? null : physicaladdress.tostring();         }         set         {             physicaladdress = value == null ? null : system.net.networkinformation.physicaladdress.parse( value );         }     }      [notmapped]     public system.net.networkinformation.physicaladdress physicaladdress     {         get;         set;     }      public static implicit operator string( wrappedphysicaladdress target )     {         return target.tostring();     }      public static implicit operator system.net.networkinformation.physicaladdress( wrappedphysicaladdress target )     {         return target.physicaladdress;     }      public static implicit operator wrappedphysicaladdress( string target )     {         return new wrappedphysicaladdress()          {              physicaladdressstring = target          };     }      public static implicit operator wrappedphysicaladdress( system.net.networkinformation.physicaladdress target )     {         return new wrappedphysicaladdress()         {             physicaladdress = target         };     }      public override string tostring()     {         return physicaladdressstring;     } } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -