Skip to content

Instantly share code, notes, and snippets.

@gabrieljoelc
Created November 7, 2013 03:03
Show Gist options
  • Save gabrieljoelc/7348244 to your computer and use it in GitHub Desktop.
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/
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