Created
June 11, 2016 14:48
-
-
Save jnm2/d419db8218872afca90234381cddbc38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Entity Framework reference type | |
public class Class1 | |
{ | |
// Not mapped by EF | |
public ComplexType ComplexProperty { get; set; } | |
// Mapped by EF convention | |
private string ComplexProperty_Prop1 | |
{ | |
get { return ComplexProperty.Prop1; } | |
set { ComplexProperty = ComplexProperty.WithProp1(value); } | |
} | |
private int ComplexProperty_Prop2 | |
{ | |
get { return ComplexProperty.Prop2; } | |
set { ComplexProperty = ComplexProperty.WithProp2(value); } | |
} | |
private string ComplexProperty_Prop3_Prop1 | |
{ | |
get { return ComplexProperty.Prop3.Prop1; } | |
set { ComplexProperty = ComplexProperty.WithProp3(ComplexProperty.Prop3.WithProp1(value)); } | |
} | |
private int ComplexProperty_Prop3_Prop2 | |
{ | |
get { return ComplexProperty.Prop3.Prop2; } | |
set { ComplexProperty = ComplexProperty.WithProp3(ComplexProperty.Prop3.WithProp2(value)); } | |
} | |
} | |
// Immutable value type | |
public struct ComplexType | |
{ | |
public ComplexType(string prop1, int prop2, NestedComplexType prop3) | |
{ | |
Prop1 = prop1; | |
Prop2 = prop2; | |
Prop3 = prop3; | |
} | |
public string Prop1 { get; } | |
public int Prop2 { get; } | |
public NestedComplexType Prop3 { get; } | |
public ComplexType WithProp1(string value) => new ComplexType(value, Prop2, Prop3); | |
public ComplexType WithProp2(int value) => new ComplexType(Prop1, value, Prop3); | |
public ComplexType WithProp3(NestedComplexType value) => new ComplexType(Prop1, Prop2, value); | |
} | |
// Immutable value type | |
public struct NestedComplexType | |
{ | |
public NestedComplexType(string prop1, int prop2) | |
{ | |
Prop1 = prop1; | |
Prop2 = prop2; | |
} | |
public string Prop1 { get; } | |
public int Prop2 { get; } | |
public NestedComplexType WithProp1(string value) => new NestedComplexType(value, Prop2); | |
public NestedComplexType WithProp2(int value) => new NestedComplexType(Prop1, value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment