您的位置:首页 > 其它

开发过程遇到的问题和解决方法(备忘)

2015-03-19 21:40 615 查看
2015-03-19

1.当项目框架为.Net Framework4.0的时候,使用EF6.0会出问题。

解决方法:将引用的EF相关dll改成EF5.0的DLL。

2.EF使用Model First方式建立数据库时,发布网站至IIS或者服务器上时,微软会采取sql登录验证而采取Windows(即连接字符串为Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=true; 时会出问题)

解决方法:将EF的连接字符串改为

<add name="Model1Container" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=./;Initial Catalog=kashishop;User Id=kashishop;Password=123;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />


3.使用EF,发布网站时,要在配置文件中添加

<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>




<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>


2015-03-21

1.unity工程中添加多个相机后出现如下警告:
There are 2 audio listeners in the scene. Please ensure there is always exactly one audio listener in the scene.
解决办法:将后添加相机的Audio Listener移除

2.unity build项目的时候报错如下:



网上搜了半天,终于找到原因,是因为用了NGUI的Label,Font属性选了个不存在的字体,不知道为什么unity会将一个不存在不支持的字体显示在选择栏,好坑爹。

2015-04-08
1.给EF的实体建立导航对象时,在更新实体对象时,报错“一个实体对象不能由多个 IEntityChangeTracker 实例引用”。
这个错误信息是由于在添加了导航属性时,必须由同一个上下文对象对实体进行更新,比如说

GoodService gs = new GoodService();
Good g = gs.LoadEntities(u => u.Id == id).FirstOrDefault();
g.Name = name;
g.Price = double.Parse(price);
g.Quantifier = quantifier;
g.Instruction = instruction;
g.TypeId = typeId;
gs.Update(g);


把Service提前,用同一个Service进行取值和更新操作就没问题。

但是像下面这样,用不同的Service对象对同一个实体的导航对象进行更新就会报此错误。

Good g = new GoodService().LoadEntities(u => u.Id == id).FirstOrDefault();
g.Name = name;
g.Price = double.Parse(price);
g.Quantifier = quantifier;
g.Instruction = instruction;
g.TypeId = typeId;
GoodService gs = new GoodService();
gs.Update(g);


使用EF更新数据时,如果要更新的对象有相关的对象(换句话说,就是要更新的表有主外键关系,或者导航关系),这些对象必须来自同一个IEntityChangeTracker 。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐