EF Codefirst获得POCO的配置 [英] EF Codefirst get POCO's configuration

查看:92
本文介绍了EF Codefirst获得POCO的配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个POCO对象(EF代码优先)

I have a POCO object (EF Code-first)

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

比起我有它的配置类:

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

我如何获得新的表名和新的StringProp名称当我在配置文件中更改它时(考虑到我有ExampleTestOfDataTypesConfig和ExampleTestOfDataTypes)

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

谢谢

推荐答案

如果您想知道映射文件中的内容,请尝试以下方法:

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);  
     }  
}  

它将所有自定义设置导出到xml中文件。最好将其命名为.edmx,然后VS.NET将能够自动将其打开。

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.

这篇关于EF Codefirst获得POCO的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆