值不能为空。参数名:源 [英] Value cannot be null. Parameter name: source

查看:3507
本文介绍了值不能为空。参数名:源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是时间问题的最大浪费我已经解决了很长的时间花了几个小时。

This is probably the biggest waste of time problem I have spent hours on solving for a long time.

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();

这给了我一个错误

值不能为空。参数名:源

Value cannot be null. Parameter name: source

的堆栈跟踪

[ArgumentNullException:值不能为空。参数名:源]
  System.Linq.Enumerable.Any(IEnumerable的 1来源,Func键 2 predicate)
  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 ......

[ArgumentNullException: Value cannot be null. Parameter name: source] System.Linq.Enumerable.Any(IEnumerable1 source, Func2 predicate) +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

I just want to add an entity to the table. The ORM is EF.

推荐答案

我有这一个而回,答案是不一定你所期望的东西。此错误消息通常作物起来,当你的连接字符串是错误的。

I had this one a while back, and the answer isn't necessarily what you'd expect. This error message often crops up when your connection string is wrong.

在猜测,你需要这样的:

At a guess, you'll need something like this:

<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 config,然后我们就可以检查。

What's happening is that it's looking for a data source in the wrong place; Entity Framework specifies it slightly differently. If you post your connection string and EF config then we can check.

这篇关于值不能为空。参数名:源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆