当我得到 System.ArgumentNullException 时,我正在使用 Visual Studio 2012 并想做一个 sql 查询(使用实体框架 5):
堆栈跟踪:
System.ArgumentNullException was unhandled
HResult=-2147467261
Message=Value cannot be null.
Parameter name: source
Source=System.Core
ParamName=source
StackTrace:
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
at Model.RavenDB.ThreadProvider_Raven.Get(Eid item, Rid forum) in c:\Users\fm\Desktop\121219scraper-mssql\Model.RavenDB\ThreadProvider_Raven.cs:line 52
at Model.RavenDB.ThreadProvider_Raven.Exsist(Eid item, Rid forum, Nullable`1& out_Item) in c:\Users\fm\Desktop\121219scraper-mssql\Model.RavenDB\ThreadProvider_Raven.cs:line 90
at Scraper.DT_Category.Download() in c:\Users\fm\Desktop\121219scraper-mssql\Scraper\1 (independent)\Download tasks\DT_Category.cs:line 115
at Scraper.DQ_ParticularForum.QueueReader(Object _this) in c:\Users\fm\Desktop\121219scraper-mssql\Scraper\1 (independent)\DQ_ParticularForum.cs:line 72
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)
InnerException:
询问:
using (var context = new Model.MsSql.Context())
{
var t = context.Threads.FirstOrDefault(s => s.ForumId == (short)forum && s.ExternalId == (int)item);
...
}
模型:
namespace Model.MsSql
{
public class Context : DbContext
{
public DbSet<Message> Messages;
public DbSet<Thread> Threads;
}
public class Message
{
public int ExternalId;
public short ForumId;
}
public class Thread
{
public int ExternalId;
public short ForumId;
}
}
我确定我错过了一些明显的东西,但任何帮助将不胜感激。