C# EntityTypeConfiguration和<;的扩展方法;数据类型>;属性配置

C# EntityTypeConfiguration和<;的扩展方法;数据类型>;属性配置,c#,entity-framework,C#,Entity Framework,使用Entity Framework,我可能会有如下配置: internal class MyDbContext : DbContext { .... protected override void OnModelCreating(DbModelBuilder mb) { builder.Entity<MyEntity>() .ToTable("MyTable", "MySchema"); builder.Entity<MyEnti

使用Entity Framework,我可能会有如下配置:

internal class MyDbContext : DbContext
{

  ....

  protected override void OnModelCreating(DbModelBuilder mb)
  {
    builder.Entity<MyEntity>()
      .ToTable("MyTable", "MySchema");

    builder.Entity<MyEntity>()
      .Property(e => e.Name)
      .IsRequired()
      .HaxMaxLength(10);

    builder.Entity<MyEntity>()
      .Property(e => e.City)
      .HaxMaxLength(10);

  }
}
内部类MyDbContext:DbContext
{
....
模型创建时受保护的覆盖无效(DbModelBuilder mb)
{
builder.Entity()
.ToTable(“MyTable”、“MySchema”);
builder.Entity()
.Property(e=>e.Name)
.IsRequired()
.HaxMaxLength(10);
builder.Entity()
.Property(e=>e.City)
.HaxMaxLength(10);
}
}
我想写一个扩展方法,这样我就可以像这样写:

    builder.Entity<MyEntity>()
      .ToTable("MyTable", "MySchema")
      .Property(e => e.Name, 
        n => n.IsRequired()
              .HaxMaxLength(10))
      .Property(e => e.City,
        c => c.HasxMaxLength(50));
builder.Entity()
.ToTable(“MyTable”、“MySchema”)
.Property(e=>e.Name,
n=>n.IsRequired()
.HaxMaxLength(10))
.地产(e=>e.城市,
c=>c.HasxMaxLength(50));
我很确定我的签名是正确的,但我不知道如何让内部管道正常工作

    public static EntityTypeConfiguration<TEntityType> Property<TEntityType>(
        this EntityTypeConfiguration<TEntityType> instance,
        Expression<Func<TEntityType, byte[]>> propertyExpression, 
        Func<BinaryPropertyConfiguration, BinaryPropertyConfiguration> propertyConfiguration)
        where TEntityType : class
    {
        Func<TEntityType, byte[]> func = propertyExpression.Compile();

        // ??

        return instance;
    }
公共静态EntityTypeConfiguration属性(
此EntityTypeConfiguration实例,
表达式属性表达式,
Func属性(配置)
其中TEntityType:类
{
Func Func=propertyExpression.Compile();
// ??
返回实例;
}

玩了一会儿之后,我意识到我不需要执行/编译其中任何一个,我只需要按照正确的顺序将参数链接在一起

    public static EntityTypeConfiguration<TEntityType> Property<TEntityType>(
        this EntityTypeConfiguration<TEntityType> instance,
        Expression<Func<TEntityType, byte[]>> propertyExpression,
        Func<BinaryPropertyConfiguration, BinaryPropertyConfiguration> propertyConfiguration)
        where TEntityType : class
    {
        propertyConfiguration(instance.Property(propertyExpression));

        return instance;
    }
公共静态EntityTypeConfiguration属性(
此EntityTypeConfiguration实例,
表达式属性表达式,
Func属性(配置)
其中TEntityType:类
{
propertyConfiguration(instance.Property(propertyExpression));
返回实例;
}