我开始更认真地使用Simple.Data并且有以下场景似乎没有用,我无法解决为什么不(可能是一些傻事,因为我一直在盯着在它几个小时)。
基本上是db结构:
活动< - > Activity_Join< - >位置
(使用连接表,活动和位置的多对多关系店应该非常简单。可以说在布里斯托尔,巴斯等地都有彩弹活动。旅行基本上是一个版本的东西(男/女) / etc)用于内容/样式。)
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)
答案 0 :(得分:2)
我刚刚在Simple.Data套件中添加了一个测试,它(在连接术语中)正是你在那里做的,不幸的是(为了回答你的问题),它通过了。
您使用的是最新版本吗?我最近将0.9.5推向了NuGet,所以更新到那将有帮助吗?如果做不到这一点,我们可以将其转交给谷歌集团,我会帮你解决它。