Metadata file not found - Data.Entity.Model
错误 3 正在编译转换: 未能找到元数据文件“F:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\..\IDE\Microsoft.Data.Entity.Design.DatabaseGeneration.dll” E:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen\SSDLToSQL10.tt 1 1 杂项文件
原错误信息:
纠结了一半天,总算在 stackoverflow 找到了答案,
http://stackoverflow.com/questions/19664833/metadata-file-not-found-data-entity-model#
(没读懂英文的可以看我下面的分析)
问题简单分析,看下创建 EF 生成模型时候产生的 SSDLToSql10.tt(这是用于 Code First 模式下生成的一个模板文件,主要是用来生成一个 DLL SQL SCRIPT [此处没深入了解,如有不妥请指教])
<#
//---------------------------------------------------------------------
// <copyright file="SsdlToSql10.tt" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//---------------------------------------------------------------------
// This T4 template generates T-SQL from an instance of
// System.Data.Metadata.Edm.StoreItemCollection, an object representation
// of the SSDL. This T-SQL is compatible with SQL , , , CE, and Azure databases.
//---------------------------------------------------------------------
// Note: We will resolve all paths in assembly directives at runtime, taking
// macros and environment variables into account (e.g. $(ProjectDir), %VS120COMNTOOLS% etc.)
#>
<#@ assembly name="System.Core" #>
<#@ assembly name="%VS120COMNTOOLS%..\IDE\Microsoft.Data.Entity.Design.DatabaseGeneration.dll"#>
<#@ assembly name="%VS120COMNTOOLS%..\IDE\EntityFramework.dll"#>
<#@ assembly name="%VS120COMNTOOLS%..\IDE\EntityFramework.SqlServer.dll" #>
<#@ assembly name="%VS120COMNTOOLS%..\IDE\EntityFramework.SqlServerCompact.dll" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Data.Entity" #>
<#@ import namespace="System.Data.Entity.Core.Metadata.Edm" #>
<#@ import namespace="Microsoft.Data.Entity.Design.DatabaseGeneration" #>
<#@ import namespace="System.Runtime.Remoting.Messaging" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ template language="C#" debug="true" hostspecific="true" #>
<#@ include file="GenerateTSQL.Utility.ttinclude"#>
<#@ output extension = ".sql" #>
<# // +++++++++++++++++++++++++++++++++++++++++++++++++
// Setup for the template (initializing variables, etc.)
// +++++++++++++++++++++++++++++++++++++++++++++++++ string databaseName = this.GetInput<string>(EdmParameterBag.ParameterName.DatabaseName.ToString());
string edmxPath = this.GetInput<string>(EdmParameterBag.ParameterName.EdmxPath.ToString());
Version targetVersion = this.GetInput<Version>(EdmParameterBag.ParameterName.TargetVersion.ToString()); DbConfiguration.SetConfiguration(new TemplateDbConfiguration()); if (false == InitializeAndValidateExistingStore())
{
#>
-- Warning: There were errors validating the existing SSDL. Drop statements
-- will not be generated.
<#
}
#>
-- --------------------------------------------------
<#
if (this.IsSQLCE) {
#>
-- Entity Designer DDL Script for SQL Server Compact Edition
<#
} else {
#>
-- Entity Designer DDL Script for SQL Server , , and Azure
<#
}
#>
-- --------------------------------------------------
-- Date Created: <#=DateTime.Now#>
<#
if (!String.IsNullOrEmpty(edmxPath))
{
#>
-- Generated from EDMX file: <#=Id(edmxPath)#>
<#
}
#>
-- -------------------------------------------------- <# if (!this.IsSQLCE)
{
#>
SET QUOTED_IDENTIFIER OFF;
GO
<# if (!String.IsNullOrEmpty(databaseName))
{
#>
USE [<#=Id(databaseName)#>];
GO
<#
}
foreach (string unescapedSchemaName in (from es in Store.GetAllEntitySets() select es.GetSchemaName()).Distinct())
{
#>
IF SCHEMA_ID(N'<#=Lit(unescapedSchemaName)#>') IS NULL EXECUTE(N'CREATE SCHEMA [<#=Id(unescapedSchemaName)#>]');
<#
}
#>
GO
<# } #> -- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
<# if (this.IsSQLCE)
{
#>
-- NOTE: if the constraint does not exist, an ignorable error will be reported.
<# } #>
-- -------------------------------------------------- <#
foreach (AssociationSet associationSet in ExistingStore.GetAllAssociationSets())
{
ReferentialConstraint constraint = associationSet.ElementType.ReferentialConstraints.Single();
string constraintName = Id(WriteFKConstraintName(constraint));
AssociationSetEnd dependentSetEnd = associationSet.AssociationSetEnds.Where(ase => ase.CorrespondingAssociationEndMember == constraint.ToRole).Single();
string schemaName = Id(dependentSetEnd.EntitySet.GetSchemaName());
string dependentTableName = Id(dependentSetEnd.EntitySet.GetTableName()); if (!this.IsSQLCE)
{
#>
IF OBJECT_ID(N'[<#=Lit(schemaName)#>].[<#=Lit(constraintName)#>]', 'F') IS NOT NULL
<# } #>
ALTER TABLE <# if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=dependentTableName#>] DROP CONSTRAINT [<#=constraintName#>];
GO
<#
}
#> -- --------------------------------------------------
-- Dropping existing tables
<# if (this.IsSQLCE)
{
#>
-- NOTE: if the table does not exist, an ignorable error will be reported.
<# } #>
-- -------------------------------------------------- <#
foreach (EntitySet entitySet in ExistingStore.GetAllEntitySets())
{
string schemaName = Id(entitySet.GetSchemaName());
string tableName = Id(entitySet.GetTableName()); if (!this.IsSQLCE)
{
#>
IF OBJECT_ID(N'[<#=Lit(schemaName)#>].[<#=Lit(tableName)#>]', 'U') IS NOT NULL
<# } #>
DROP TABLE <# if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=tableName#>];
GO
<#
}
#> -- --------------------------------------------------
-- Creating all tables
-- -------------------------------------------------- <#
foreach (EntitySet entitySet in Store.GetAllEntitySets())
{
string schemaName = Id(entitySet.GetSchemaName());
string tableName = Id(entitySet.GetTableName());
#>
-- Creating table '<#=tableName#>'
CREATE TABLE <# if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=tableName#>] (
<#
for (int p = ; p < entitySet.ElementType.Properties.Count; p++)
{
EdmProperty prop = entitySet.ElementType.Properties[p];
#>
[<#=Id(prop.Name)#>] <#=prop.ToStoreType()#> <#=WriteIdentity(prop, targetVersion)#> <#=WriteNullable(prop.Nullable)#><#=(p < entitySet.ElementType.Properties.Count - ) ? "," : ""#>
<#
}
#>
);
GO <#
}
#>
-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- -------------------------------------------------- <#
foreach (EntitySet entitySet in Store.GetAllEntitySets())
{
string schemaName = Id(entitySet.GetSchemaName());
string tableName = Id(entitySet.GetTableName());
#>
-- Creating primary key on <#=WriteColumns(entitySet.ElementType.GetKeyProperties(), ',')#> in table '<#=tableName#>'
ALTER TABLE <# if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=tableName#>]
ADD CONSTRAINT [PK_<#=tableName#>]
PRIMARY KEY <# if (!IsSQLCE) {#>CLUSTERED <#}#>(<#=WriteColumns(entitySet.ElementType.GetKeyProperties(), ',')#> <# if (!IsSQLCE) {#>ASC<#}#>);
GO <#
}
#>
-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- -------------------------------------------------- <#
foreach (AssociationSet associationSet in Store.GetAllAssociationSets())
{
ReferentialConstraint constraint = associationSet.ElementType.ReferentialConstraints.Single();
AssociationSetEnd dependentSetEnd = associationSet.AssociationSetEnds.Where(ase => ase.CorrespondingAssociationEndMember == constraint.ToRole).Single();
AssociationSetEnd principalSetEnd = associationSet.AssociationSetEnds.Where(ase => ase.CorrespondingAssociationEndMember == constraint.FromRole).Single();
string schemaName = Id(dependentSetEnd.EntitySet.GetSchemaName());
string dependentTableName = Id(dependentSetEnd.EntitySet.GetTableName());
string principalTableName = Id(principalSetEnd.EntitySet.GetTableName());
#>
-- Creating foreign key on <#=WriteColumns(constraint.ToProperties, ',')#> in table '<#=dependentTableName#>'
ALTER TABLE <#if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=dependentTableName#>]
ADD CONSTRAINT [<#=WriteFKConstraintName(constraint)#>]
FOREIGN KEY (<#=WriteColumns(constraint.ToProperties, ',')#>)
REFERENCES <# if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=principalTableName#>]
(<#=WriteColumns(constraint.FromProperties, ',')#>)
ON DELETE <#=GetDeleteAction(constraint)#> ON UPDATE NO ACTION;
<#
// if the foreign keys are part of the primary key on the dependent end, then we should not add a constraint.
if (!dependentSetEnd.EntitySet.ElementType.GetKeyProperties().Take(constraint.ToProperties.Count()).OrderBy(r => r.Name).SequenceEqual(constraint.ToProperties.OrderBy(r => r.Name)))
{
#> -- Creating non-clustered index for FOREIGN KEY '<#=WriteFKConstraintName(constraint)#>'
CREATE INDEX [IX_<#=WriteFKConstraintName(constraint)#>]
ON <#if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=dependentTableName#>]
(<#=WriteColumns(constraint.ToProperties, ',')#>);
<#
}
#>
GO <#
}
#>
-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------
SSDLToSql10.tt
这里面就可以看到它引用了这几个程序集
<#@ assembly name="System.Core" #>
<#@ assembly name="%VS120COMNTOOLS%..\IDE\Microsoft.Data.Entity.Design.DatabaseGeneration.dll"#>
<#@ assembly name="%VS120COMNTOOLS%..\IDE\EntityFramework.dll"#>
<#@ assembly name="%VS120COMNTOOLS%..\IDE\EntityFramework.SqlServer.dll" #>
<#@ assembly name="%VS120COMNTOOLS%..\IDE\EntityFramework.SqlServerCompact.dll" #>
索性我发现这几个程序集确实没在编译报错的路径中,我直接 copy 粘贴到了指定的目录下甚至还在编译器中引用,编译依旧如此。有点棘手!
最后看了老外的分析,说是 visual studio 安装的环境变量值路径不对,后来才一愣发现真是这个问题
控制面板->系统->高级系统设置->高级->环境变量
最终才明白原来编译的路径依据是根据环境变量来的,真是图样图森破
Metadata file not found - Data.Entity.Model的更多相关文章
- The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name
可以强迫部署EntityFramework.SqlServer.dll这个文件到输出目录 找到1个老外的帖子,戳这里(本人测试无效,大家有可能试一下..) 解决方案以下: 在EF的上下文代码CS文件( ...
- 运用模型绑定和web窗体显示和检索数据(Retrieving and displaying data with model binding and web forms)
原文 http://www.asp.net/web-forms/overview/presenting-and-managing-data/model-binding/retrieving-data ...
- 写一个system.data.entity的simpledatarepo,实现crudq这些功能,不需要引入entityframework,直接可以使用,用到objectset
note:you can delete reference of entityframework when using this classes.it`s just a simple repohelp ...
- Metadata file 'xxx.dll' could not be found 已解决
最近学习三层架构,在网上找了个权限管理的源码研究,发现编译不通过,到处都是Metadata file 'xxx.dll' could not be found,找了两天原因都没找到答案. 然后试着去编 ...
- 报错:无法将类型"System.Data.EntityState"隐式转换为"System.Data.Entity.EntityState"
报错:无法将类型"System.Data.EntityState"隐式转换为"System.Data.Entity.EntityState". 出错语句停留 ...
- 未能从程序集 C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Data.Entity.Build.Tasks.dll 加载任务“EntityClean”
问题: 未能从程序集 C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Data.Entity.Build.Tasks.dll 加载任务“Entity ...
- Method 'ExecuteAsync' in type 'System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy' does not have an implementation
一.错误信息 Entity Framework 6.0数据迁移:Add-Migration XXXX 命令发生错误 System.Reflection.TargetInvocationExceptio ...
- 序列化类型 System.Data.Entity.DynamicProxies 的对象时检测到循环引用
学习 EF Code First+MVC 时遇到了在请求JsonResult时出现 序列化类型 System.Data.Entity.DynamicProxies 的对象时检测到循环引用 的异常,原因 ...
- ef 对象无法序列化的问题(System.Data.Entity.DynamicProxies)
错误提示: System.InvalidOperationException: 生成 XML 文档时出错. ---> System.InvalidOperationException: 不应是类 ...
随机推荐
- 一个简单的创建圆角图像的UIImage扩展实现
- (UIImage *)roundedCornerImageWithCornerRadius:(CGFloat)cornerRadius { CGFloat w = self.size.width; ...
- UIScrollView的属性总结
contentSize是scrollview可以滚动的区域,比如frame = (0 ,0 ,320 ,480) contentSize = (320 ,960),代表你的scrollview可以上下 ...
- HDU 1018 Big Number
LINK:HDU 1018 题意:求n!的位数~ 由于n!最后得到的数是十进制,故对于一个十进制数,求其位数可以对该数取其10的对数,最后再加1~ 易知:n!=n*(n-1)*(n-2)*...... ...
- 复制带有random指针的单链表
如图1所示,有一条单链表,其节点除了有next指针外,还有一个random指针.random指针可指向单链表中的任意节点,包括它自身.random指针一旦指定,便不再更改.请设计算法,复制此单链表,并 ...
- HDU 5477 A Sweet Journey 水题
A Sweet Journey Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- 戴尔笔记本win8.1+UEFI下安装Ubuntu14.04过程记录
瞎扯:笔记本刚买不久就想装ubuntu来着,但结果发现BIOS启动方式为UEFI,网上一搜索发现跟曾经的双系统安装方法不一样,看详细教程感觉相当复杂,并且也有点操心折腾跪了这新本本所以一直没有动手.但 ...
- redis实现spring-redis-data的入门实例
redis的客户端实现.主要分为spring-redis-data .jredis. 记录下spring-redis-data的学习心得:spring-redis-data 中我目前主要用了它的存.取 ...
- 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)
Android 平台提供了两类动画. 一类是Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转.平移.放缩和渐变). 第二类就是 Frame动画,即顺序的播放事先做好的图像,与g ...
- com.domain.bean
package com.domain.bean; import java.util.LinkedHashMap; import java.util.Map; public class TmpBean ...
- Helpers\Date
Helpers\Date The Date helper is used for calculations with dates. Date::difference($from, $to, $type ...