EF Codefirst获得POCO的配置

编程入门 行业动态 更新时间:2024-10-23 22:25:51
本文介绍了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的配置

本文发布于:2023-07-27 11:55:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222318.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:EF   Codefirst   POCO

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!