EF Codefirst get POCO's configuration

主宰稳场 提交于 2019-12-25 03:34:10

问题


I have a POCO object (EF Code-first)

public class ExampleTestOfDataTypes
{
        public string StringProp { get; set; }
}

Than i have its configuration class:

public class ExampleTestOfDataTypesConfig : EntityTypeConfiguration<ExampleTestOfDataTypes>
    {
        public ExampleTestOfDataTypesConfig()
        {
            ToTable("CustomTableName");
            this.Property(m => m.StringProp).HasColumnName("CustomString");
        }
    }

How can i get the new Tablename and new StringProp name when i changed it in config file (considering i have ExampleTestOfDataTypesConfig and ExampleTestOfDataTypes)

Thanks


回答1:


If you want to know what's inside the mappings file, try this method:

void ExportMappings(DbContext context, string edmxFile)  
{  
     var settings = new XmlWriterSettings { Indent = true };  
     using (XmlWriter writer = XmlWriter.Create(edmxFile, settings))  
     {  
         System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(context, writer);  
     }  
}  

It will export all of your custom settings to an xml file. It's better to name it .edmx and then VS.NET will be able to open it automatically.



来源:https://stackoverflow.com/questions/10738382/ef-codefirst-get-pocos-configuration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!