更新时间:2023-02-20 20:52:07
好,您需要加载上下文,因为它需要调用 OnModelBuilding(DbModelBuilder)
至少要做一次生意;
Well, you need to load the context because it needs to call OnModelBuilding(DbModelBuilder)
at least once to do it's business; otherwise there is no model to interrogate.
如果需要,可以使用 EdmxWriter
;
If you want, you can store off the information as XML using EdmxWriter
;
public static string ToEdmx(this System.Data.Entity.DbContext context)
{
var sb = new StringBuilder();
using (var textWriter = new StringWriter(sb))
using (var xmlWriter = System.Xml.XmlWriter.Create(textWriter, new System.Xml.XmlWriterSettings { Indent = true, IndentChars = " " }))
{
System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(context, xmlWriter);
textWriter.Flush();
}
return sb.ToString();
}
这将为您提供带有数据模型的XML文档。您可能可以通过一个进程将其保存到磁盘,然后在TT文件中查询该文件。
This will give you an XML document with the data model. You can probably save that to disk in one process, and interrogate that file in your TT file.