问题
I'm currently experiencing the issue mentioned here (and several other places): Subsonic 3 Linq Projection Issue
This is occurring using the 3.0.0.4 release package, and it also occurs when I grab the latest from GitHub and build it.
I am using the LINQ Templates.
I have this code:
var newModel = new ViewModels.HomeIndexViewModel() {
PulseListViewModel =
new ViewModels.PulseListViewModel
{
Pulses = from p in _pulseQuery
join a in _accountQuery on p.AccountId equals a.AccountId
orderby p.CreateDate descending
select new PulseListViewModel.Pulse()
{
AccountName = a.Name
, Category = p.Category
, CreateDate = p.CreateDate
, Link = p.Link
, Message = p.Message
, Source = p.Source
, Title = p.Title
}
}
};
But AccountName is always null.
If I change the AccountName to Name:
var newModel = new ViewModels.HomeIndexViewModel() {
PulseListViewModel =
new ViewModels.PulseListViewModel
{
Pulses = from p in _pulseQuery
join a in _accountQuery on p.AccountId equals a.AccountId
orderby p.CreateDate descending
select new PulseListViewModel.Pulse()
{
Name = a.Name
, Category = p.Category
, CreateDate = p.CreateDate
, Link = p.Link
, Message = p.Message
, Source = p.Source
, Title = p.Title
}
}
};
It works fine. But that's not acceptable in our project; I can't always make the names line up (besides the fact that it would make things less clear if I could).
But I'm quite confused because it would seem this issue's been fixed:
"Fixed issue where Projections were returning null or empty settings"
-- http://blog.wekeroad.com/2010/03/21/subsonic-3-0-0-4-released
So, can anyone tell me: Is this issue not fixed, and do I have to apply the changes found here at http://github.com/funky81/SubSonic-3.0/commit/aa7a9c1b564b2667db7fbd41e09ab72f5d58dcdb to make this work? Or am I missing something. Because looking through the current SubSonic source it appears this fix has been included. I feel like this should be simple and work, but instead I've spent an inordinate amount of time on it.
回答1:
If you (me) modify SubSonic.Core according to the answer here: Subsonic 3.0 and linq
Then the projection works correctly.
However, I consider this a very bad solution as it requires forking a project and introducing an order of magnitude performance decrease.
回答2:
Could you send me a little bit more code (especially what's behind _pulseQuery and _accountQuery) so I can fix this issue. Are you using SimpleRepository or the ActiveRecord approach or Query objects directly?
回答3:
Reviving an old topic here, but in case someone searches for this later...
I also "fixed" this same issue, and put some explanation in the comments, in my fork on GitHub in this commit: https://github.com/rally25rs/SubSonic-3.0/commit/61af6aeb2ebb95f486d8df533bf13c8754d443e2
There is actually a slightly deeper issue here too. If you choose to use the "standard .NET built-in" projections, then some of the SubSonic unit tests start to fail, because SS does some extra stuff in its projection generation that the .NET projection doesn't do, so some of the expected functionality of SS doesn't work.
Personally, I think that, and the slower performance (though I haven't noticed a speed decrease) is a small price to pay for correct data.
来源:https://stackoverflow.com/questions/3111583/subsonic-3-linq-projection-issue-fixed-or-no