我使用Visual Studio 2012和想要做一個SQL查詢(使用實體框架5)當我System.ArgumentNullException爲:獲得異常使用LINQ
堆棧跟蹤:
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:
QUERY:
using (var context = new Model.MsSql.Context())
{
var t = context.Threads.FirstOrDefault(s => s.ForumId == (short)forum && s.ExternalId == (int)item);
...
}
MODEL:
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;
}
}
我確定我錯過了一些明顯的東西,但任何幫助將不勝感激。
也許你應該向我們展示你想要查詢數據庫的代碼。 –
是的,那肯定會讓任何人都更容易幫忙......對不起。 – Niko