如何解决值不能为空参数名称:来源
我前一段时间有这个,答案不一定是您期望的。当您的连接字符串错误时,通常会出现此错误消息。
大概,您需要这样的东西:
<connectionStrings>
<add name="hublisherEntities" connectionString="Data Source=localhost;Initial Catalog=hublisher;Integrated Security=True;" providerName="System.Data.sqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=localhost;Initial Catalog=hublisher;Integrated Security=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
发生的事情是它在错误的位置寻找数据源。实体框架对它的指定稍有不同。如果您发布连接字符串和EF配置,那么我们可以进行检查。
解决方法
这很可能是我浪费了很长时间解决的时间浪费最大的问题。
var db = new hublisherEntities();
establishment_brands est = new establishment_brands();
est.brand_id = 1;
est.establishment_id = 1;
est.price = collection["price"];
est.size = collection["size"];
db.establishment_brands.Add(est);
db.SaveChanges();
这给我一个错误
值不能为空。参数名称:来源
的堆栈跟踪
[ArgumentNullException:值不能为null。参数名称:source]
System.Linq.Enumerable.Any(IEnumerable1 source,Func
2谓词)+4083335
System.Data.Entity.Internal.InternalContext.WrapUpdateException(UpdateException
updateException)+87
System.Data.Entity.Internal.InternalContext.SaveChanges()+ 193
System.Data.Entity.Internal.LazyInternalContext.SaveChanges()+33
System.Data.Entity.DbContext.SaveChanges()+20 … …
我只想向表添加一个实体。ORM是EF。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。