开发者

NHibernate 3.0 - Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."

开发者 https://www.devze.com 2023-02-15 02:28 出处:网络
We are trying to upgrade to NHibernate 3.0 and now i am having problem with the following Linq query. It returns \"Only one expression can be specified in the select list when the subquery is not intr

We are trying to upgrade to NHibernate 3.0 and now i am having problem with the following Linq query. It returns "Only one expression can be specified in the select list when the subquery is not introduced with EXISTS." error.

This is the linq query in the controller.

var list = (from item in ItemTasks.FindTabbedOrDefault(tab)
                    select new ItemSummary
                               {
                                   Id = item.Id,
                                   LastModifyDate = item.LastModifyDate,
                                   Tags = (from tag in item.Tags
                                           select new TagSummary
                                                      {
                                                          ItemsCount = tag.Items.Count,
                                                          Name = tag.Name
                                                      }).ToList(),
                                   Title = item.Title
                               });

and the following is the sql generated for this query

select   TOP ( 1 /* @p0 */ ) item0_.Id             as col_0_0_,
                 item0_.LastModifyDate as col_1_0_,
                 (select (select cast(count(* ) as INT)
                          from   dbo.ItemsToTags items3_,
                                 dbo.Item item4_
                          where  tag2_.Id = items3_.Tag_id
                                 and items3_.Item_id = item4_.Id),
                         tag2_.Name
                  from   dbo.ItemsToTags tags1_,
                         dbo.Tag tag2_
                  where  item0_.Id = tags1_.Item_id
                         and tags1_.Tag_id = tag2_.Id) as col_2_0_,
                 item0_.Title          as col_3_0_ from     dbo.Item item0_ order by item0_.ItemPostDate desc

ps:If i remove the Tags property in the linq query, it works fine.

Where is th开发者_开发知识库e problem in the query?

Thanks in advance.


I've got the same Generic ADO Exception error, I think it's actually the limitation of SQL server; Is it possible somehow load object graph with projections in collections?

If I try this one:

var cats = q.Select(t => new cat()
                                          {
                                              NickName = t.NickName,
                                              Legs = t.Legs.Select(l => new Leg()
                                                                            {
                                                                                Color = l.Color,
                                                                                Size = l.Size
                                                                            }).ToList()
                                          }).ToList();

That does the same error..

0

精彩评论

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