Created
November 7, 2013 03:03
-
-
Save gabrieljoelc/7348244 to your computer and use it in GitHub Desktop.
How to map private/protected properties in Entity Framework code first. From http://blog.cincura.net/232731-mapping-private-protected-properties-in-entity-framework-4-x-code-first/
This file contains hidden or 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
public partial class FooBar | |
{ | |
private int ID { get; set; } | |
private string Something { get; set; } | |
} | |
public partial class FooBar | |
{ | |
public class PropertyAccessExpressions | |
{ | |
public static readonly Expression<Func<FooBar, int>> ID = x => x.ID; | |
public static readonly Expression<Func<FooBar, string>> Something = x => x.Something; | |
} | |
} | |
class FooBarMap : EntityTypeConfiguration<FooBar> | |
{ | |
public FooBarMap() | |
{ | |
Property(FooBar.PropertyAccessorExpressions.Id); | |
Property(FooBar.PropertyAccessorExpressions.Something); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment