开发者

SimpleData complex join and projection to poco type

I'm starting to use Simple.Data a bit more seriously and have the following scenario that doesn't seem to be working and I can't wrap my head around why not (probably something silly as I've been staring at it for a few hours).

Basically db structure:

Activity <-> Activity_Join <-> Location

(A many to many relationshop using a join table, an activity and location should be pretty straightforward. Say a paintballing activity could be at both Bristol, Bath and so on. Trip is basically a version'ing thing (male/female/etc) for content/styling.)

Simple.Data query:

return _database.Activity.Query()
.Join(_database.Activity_Join).On(_database.Activity.ID_Activity == _database.Activity_Join.ID_Activity)
.Join(_database开发者_StackOverflow社区.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; }
    }
}

The aim of the query is to fetch the Activity per Trip and tag on the ID_Location guid to be able to figure out where the activity takes place. Further on in my code I hold the list of locations in memory so will use LINQ rather than DB for a few other reasons.

The problem is it won't cast to the POCO! The error and stack trace is:

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)


I just added a test to the Simple.Data suite which does (in join terms) exactly what you're doing there, and unfortunately (for the purposes of answering your question), it passes.

Are you using the latest version? I've recently pushed 0.9.5 to NuGet, so maybe updating to that will help? Failing that, we could take this over to the Google Group and I'll help you resolve it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜