求教EntityFramework 6.0 TT模板的使用
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF6.Utility.CS.ttinclude"#><#@
output extension=".cs"#><#
const string inputFile = @"DataModel.edmx";
var textTransform = DynamicTextTransformation.Create(this);
var code = new CodeGenerationTools(this);
var ef = new MetadataTools(this);
var typeMapper = new TypeMapper(code, ef, textTransform.Errors);
var loader = new EdmMetadataLoader(textTransform.Host, textTransform.Errors);
var itemCollection = loader.CreateEdmItemCollection(inputFile);
var modelNamespace = loader.GetModelNamespace(inputFile);
var codeStringGenerator = new CodeStringGenerator(code, typeMapper, ef);
var container = itemCollection.OfType<EntityContainer>().FirstOrDefault();
if (container == null)
{
return string.Empty;
}
#>
//使用TT模板生成代码的片段
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
..........................................
.................................
报4个错如下
1.未能找到类型或命名空间名称“TypeMapper”(是否缺少 using 指令或程序集引用?)
2.未能找到类型或命名空间名称“CodeStringGenerator”(是否缺少 using 指令或程序集引用?)
3.非静态字段、方法或属性“System.Data.Entity.Core.Metadata.Edm.ItemCollection.GetItems<T>()”要求对象引用
4.正在编译转换: 当前上下文中不存在名称“ArgumentNotNull”
如果使用EF.Utility.CS.ttinclude而不使用EF6.Utility.CS.ttinclude 这样写的话.可以正常编译但是有个警告.
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ include file="EF.Utility.CS.ttinclude"#> //引进TT模板的命名空间
<#@ output extension=".cs" #>
<# CodeGenerationTools code = new CodeGenerationTools(this);
MetadataLoader loader = new MetadataLoader(this);
CodeRegion region = new CodeRegion(this, 1);
MetadataTools ef = new MetadataTools(this);
string inputFile = @"DataModel.edmx";
EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);
string namespaceName = code.VsNamespaceSuggestion();
EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);
#>
//使用TT模板生成代码的片段
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
............................
.........................................
警告内容如下(原因是DataModel.edmx默认使用的是EF6.Utility.CS.ttinclude,所以警告版本不对):
1.正在运行转换: 输入文件似乎使用了此模板所不支持的架构版本。此可能会导致编译错误。请使用“添加新的生成项”以添加更新的模板。
所以我想除去这个警告 把EF.Utility.CS.ttinclude换成EF6.Utility.CS.ttinclude 改用EF6的TT模板.
请各位不吝赐教.
相关推荐
扩展ASP.NET MVC三层框架且使用StructureMap实现依赖注入1-Model层
在创建数据模型时,我们没有采用默认的.tt文件方式,而是选择了更传统的方法。首先,按照默认步骤创建数据模型,然后删除生成的.tt文件。
fengmian123
fengmian123
QYR-18900-2026-2032全球与中国智能旋转导向钻井系统市场现状及未来发展趋势 Sample-shijunzhong.docx
QYR-18900-2026-2032全球与中国智能旋转导向钻井系统市场现状及未来发展趋势 Sample-shijunzhong.docx
XERJ 是一款受到社区信赖的本地 AI 搜索引擎
XERJ 是一款受到社区信赖的本地 AI 搜索引擎,能自动为任意文件夹建立索引,让编程智能体直接检索所需代码,省去逐个读取文件消耗的 token。它的主要用途是参考现有实现来写代码(reference coding):接到任务后,智能体下载与任务相关的开源仓库,建立索引,再查阅这些项目的解决方法。 在一项对照研究中,这种做法让智能体的输出 token 用量降至原来的约 1/2.7,同时保持 16/16 的任务完成率(案例研究)。用户在日常开发中报告的用量约为原来的 1/5(使用反馈)。有了可检索的参考实现,较小、较便宜的模型也可能胜过只凭记忆工作的昂贵模型,减少反复修改的次数。把下面这段提示词交给智能体即可开始
DocRes.Vulkan.WinForms.VS2022-Source-r1.1-20261016-102846-206.zip
DocRes.Vulkan.WinForms.VS2022-Source-r1.1-20261016-102846-206.zip 博客地址:https://blog.csdn.net/lw112190/article/details/168119884


.NET Framework
