求教EntityFramework 6.0 TT模板的使用

「已注销」 「已注销」 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
用EF.Utility.CS.ttinclude我按照这样写代码的话,会报错.

<#@ 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层

本篇文章将向大家介绍如何添加Service和Repository层并且使用StructureMap把Service层注入到Controller,把Repository注入到Service层。Service层主要是我们的业务逻辑层,这一层不和底层的Database打交道,和Database打交道的是Repository数据持久层。本篇文章通过使用StructureMap依赖注入使Controller,Service,Repository三层的耦合度降到最低。本系统使用NorthWind开源数据,并且使用EntityFramework5.0实现对数据库的Object映射。开始正题之前先来看一下成型

weixin_38669793

高校技术转移办公室人员在推广科技成果时,如何解决技术推介材料制作繁琐、缺乏专业性的问题?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

利用 MATLAB 仿真均匀平面波极化的传播图像(线极化,圆极化).zip

1.版本:matlab2014a/2019b/2024b 2.附赠案例数据可直接运行。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。

海神之光

产业园区运营如何通过智能手段精准匹配产业需求与技术供给?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

政府科技管理者在推动科技成果转化过程中,如何有效解决供需信息匹配不精准的问题?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN
评论 4
收藏 已收藏
分享
返回顶部
「已注销」
.NET Framework 17,748 成员 24,324 内容