samedi 4 novembre 2017

Reflection Emit a sub class of EntityTypeConfiguration (Entity Framework)

I have a need to Reflection Emit a sub class of EntityTypeConfiguration. In the constructor of the class, it will call Map method and Property method of the parent class. I'm having difficulty to pass a method or LINQ expression as parameters to the methods. Here is the class and the constructor looks like:

    public class MyConfiguration : EntityTypeConfiguration<MyEntity>
    {
        public MyConfiguration()
        {
            Map(c => c.MapInheritedProperties()); 

            Property(e => e.Name).HasMaxLength(100);
...

I have the constructor builder created:

 var constructorGenerator = constructorBuilder.GetILGenerator();

But I don't know the proper way to emit the code for those two lines of the code (calling Map and Property methods.)

The signature of the Map method is:

   public EntityTypeConfiguration<TEntityType> Map(Action<EntityMappingConfiguration<TEntityType>> entityMappingConfigurationAction);

The signature of the Propery method is:

  public StringPropertyConfiguration Property(Expression<Func<TStructuralType, string>> propertyExpression);

Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire