惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - Inrie

[原创]MongoDB、HandlerSocket和MySQL性能测试及其结果分析 [原创]HandlerSocket系列(三):性能及其性能优化 [原创]HandlerSocket系列(二):架构、特点及其应用场景 [原创]HandlerSocket系列(一):由来 SD2.0 2009大会一些感想 在Windows Server 2008集群上做Sql Server 2008集群 解决Azure Project中使用Asp.net MVC RC会让VS崩溃的补丁 [译]剖析ASP.Net MVC Application 让VS 2008也可以用Mobile Web Form 几个不错的WCF Tools ADO.NET Entity Framework Beta3的一些问题 善待你的眼睛-使用微软专为程序员设计的Consolas字体 [推荐]ASP.NET 应用程序的扩展策略 [翻译+推荐]你需要知道的:WCF、WF、ADO.NET SyncServices和ClickOnce Unity Application Block 1.0系列文章 Unity Application Block 1.0系列(7): Lifetime Managers Unity Application Block 1.0系列(6): 杜绝循环引用 Unity Application Block 1.0系列(5): 使用BuildUp让已存在对象实例也支持依赖注入 Unity Application Block 1.0系列(4): 方法调用注入(Method Call Injection )
如何发布Ado.net Entity Framework EDM
Inrie · 2008-04-23 · via 博客园 - Inrie

前言

在开发基于Ado.net Entity Framework的程序时,通常都是把EDM ( 实体数据模型 ) 单独放在的一个Class Library里。

在发布该Class Library时需要注意一些事项,否则可能会出现些问题。

开始

看看下图,解决方案里包括两个Project:EFDemo.Console 和 EFDemo.Models 。这里我把EDM都放在 EFDemo.Models Class Library里。

EF1.jpg
在  EFDemo.Models Class Library 中添加一个"ADO.NET Entity Data Model" 项 ,名为"UserModel"。 通过向导配置连接等操作后就会创建一个EDM。EDM包括三个文件(.csdl、.msl 和.ssdl 文件)。

创建完EDM后会在配置文件(这里是App.Config)的<connectionStrings>节点里添加一些信息。如例子中创建UserModel.edmx后会在配置文件中添加一个子节点:

<connectionStrings>
    <add name="UserEntities" connectionString="metadata=.\UserModel.csdl|.\UserModel.ssdl|.\UserModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=xxxxxx;Initial Catalog=SAASDB;Persist Security Info=True;User ID=sa;Password=xxx;MultipleActiveResultSets=False&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

注意突出显示的“metadata=.\UserModel.csdl|.\UserModel.ssdl|.\UserModel.msl”,在这里指定这三个文件的位置,".\"表示Build后这三个文件会被部署到"Build Output Path"位置。

回到例子中,EFDemo.Console Project 引用 EFDemo.Models Project,这样就可以在 EFDemo.Console Project 中使用 UserModel 了,写完代码后,把上面配置文件信息Copy到EFDemo.Console Project 的App.config中, Ctrl + F5 运行,发现出现下面错误信息:

System.Data.MetadataException: The specified metadata path is not valid. A valid path must be either an existing directory, an existing file with extension '.csdl', '.ssdl', or '.msl', or a URI that identifies an embedded resource.

明显看出是找不到UserModel.csdl、UserModel.ssdl和UserModel.msl这三个文件,到EFDemo.Console的Build Output Path中看确实没有。

有一种解决方法是,每次Build完EFDemo.Models Project后,Copy这三个文件到EFDemo.Console Project的bin里,但是这种做法明显不是最好的。

可以通过以下的配置来更好的解决这问题。

1.打开UserModel Model的属性面板,设置“Metadata Artifact Processing ” 选项的值为“Embed in Output Assembly ”。表示这三个文件会被嵌入到Assembly里。

EF2.jpg

2. 打开UserModel.edmx项的属性面板,确认Build Action值为"EntityDeploy"。

EF3.jpg

以上配置完成之后配置文件中的UserEntities节点值自动改为:

  <connectionStrings>
    <add name="UserEntities" connectionString="metadata=res://*/UserModel.csdl|res://*/UserModel.ssdl|res://*/UserModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=xxxxxx;Initial Catalog=SAASDB;Persist Security Info=True;User ID=sa;Password=xxx;MultipleActiveResultSets=False&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

注意看突出显示的"metadata=res://*/UserModel.csdl|res://*/UserModel.ssdl|res://*/UserModel.msl"。"*"表示它会去所有的Aseembly中找这三个被嵌入在Assembly中的文件。当然如果我们明确知道这三个文件放在EFDemo.Models.dll 这个Assembly中的话,应该指定只在该Assembly中找,而不要浪费时间在所有Assembly中找:

  <connectionStrings>
    <add name="UserEntities" connectionString="metadata=res://EFDemo.Models/UserModel.csdl|res://EFDemo.Models/UserModel.ssdl|res://EFDemo.Models/UserModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=xxxxxx;Initial Catalog=SAASDB;Persist Security Info=True;User ID=sa;Password=xxx;MultipleActiveResultSets=False&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

把这些配置信息更新到EFDemo.Console Project 的App.config中,Ctrl + F5, 运行正常。

作者:Inrie (洪晓军)


出处:http://www.cnblogs.com/inrie