我開始使用Simple.Data更嚴重一點,並有以下情況似乎並沒有工作,我不能包住我的頭爲什麼不可以(可能有些愚蠢,因爲我一直盯着它幾個小時)。SimpleData複雜的加入和投影到poco類型
基本上分貝結構:
活動< - > Activity_Join < - >位置
(使用一個連接表,活動和位置應該是相當簡單的多對多relationshop說一個彩彈射擊活動可能。是在兩個布里斯托,巴斯等旅行基本上是一個version'ing事情(男/女/等)的含量/造型)
Simple.Data查詢:。
return _database.Activity.Query()
.Join(_database.Activity_Join).On(_database.Activity.ID_Activity == _database.Activity_Join.ID_Activity)
.Join(_database.Location).On(_database.Activity_Join.ID_Location == _database.Location.ID_Location)
.Where(_database.Activity.ID_trip == idTrip &&
_database.Activity.Activity_Time == 'D' &&
_database.Activity.Is_Public == true)
.Select(
_database.Activity.ID_Activity
, _database.Location.ID_Location
, _database.Activity.ID_Trip
, _database.Activity.Activity_Name
, _database.Activity.Adrenaline_Factor
, _database.Activity.Relaxation_Factor
, _database.Activity.Fun_Factor
, _database.Activity.Activity_Description
, _database.Activity.Activity_Extra_Info
, _database.Activity.Activity_Time
, _database.Activity.Activity_Price
, _database.Activity.Activity_Duration
, _database.Activity.Activity_Image
, _database.Activity.Is_Public).Cast<Activity>();
POCO:
using System;
namespace Blah.Models.POCOs
{
public class Activity
{
public Guid ID_Activity { get; set; }
public Guid ID_Location { get; set; }
public Guid ID_Trip { get; set; }
public string Activity_Name { get; set; }
public int Adrenaline_Factor { get; set; }
public int Relaxation_Factor { get; set; }
public int Fun_Factor { get; set; }
public string Activity_Description { get; set; }
public string Activity_Extra_Info { get; set; }
public string Activity_Time { get; set; }
public decimal Activity_Price { get; set; }
public string Activity_Duration { get; set; }
public string Activity_Image { get; set; }
public bool Is_Public { get; set; }
}
}
查詢的目的是獲取每趟和標籤的活動上ID_Location GUID要能夠找出其中的活動發生。在我的代碼中,我保存了內存中的位置列表,所以會使用LINQ而不是DB出於其他一些原因。
問題是它不會投射到POCO!錯誤和堆棧跟蹤是:
Object reference not set to an instance of an object.
at Simple.Data.Ado.Joiner.<GetJoinClauses>d__a.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
at System.Linq.Enumerable.<DistinctIterator>d__81`1.MoveNext()
at System.String.Join(String separator, IEnumerable`1 values)
at Simple.Data.Ado.QueryBuilder.HandleJoins()
at Simple.Data.Ado.QueryBuilder.Build(SimpleQuery query, IEnumerable`1& unhandledClauses)
at Simple.Data.Ado.AdoAdapter.RunQuery(SimpleQuery query, IEnumerable`1& unhandledClauses)
at Simple.Data.SimpleQuery.Run()
at Simple.Data.SimpleQuery.Cast[T]()
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at blahh.Models.Site.SitemapGenerator.GetDayActivitiesPerTrip(Guid idTrip) in D:\Projects\blah\blahh\Models\Site\SitemapGenerator.cs:line 39
at blahh.Models.Site.SitemapGenerator.Generate() in D:\Projects\blah\blahh\Models\Site\SitemapGenerator.cs:line 80
at blahh.Controllers.AdminController.Generate_Sitemap() in D:\Projects\blah\blahh\Controllers\AdminController.cs:line 1360
at lambda_method(Closure , ControllerBase , Object[])
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
我注意到stacktrace中的一個'System.String.Join()',你不像你認爲的那樣是LINQ。 –
Erm,LINQ註釋試圖顯示代碼正在進行的位置,以及爲什麼我不想要更多的位置表列。我認爲System.String.Join()來自Simple.Data? – Phil