Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map System.Version as Complex Type in Entity Framework 6

I have a System.Version object in one of my POCO entities using a Code First Entity Framework 6 application. I'd like to map it to the database as:

table Diagnostics
  column ApplicationVersionMajor int
  column ApplicationVersionMinor int
  column ApplicationVersionBuild int
  column ApplicationVersionRevision int

How do I do that when the class is something like:

class Diagnostics 
{
  public System.Version ApplicationVersion { get; set; }
}

I know I can decorate my own value objects with a [ComplexType] attribute; I just don't know how I would do this for a framework type.

like image 475
Michael Hedgpeth Avatar asked Feb 07 '26 03:02

Michael Hedgpeth


1 Answers

Since System.Version is a class it can be a complex type. You can mark it as a complex type with fluent interface.

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.ComplexType<System.Version>();
}
like image 200
bubi Avatar answered Feb 09 '26 03:02

bubi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!