Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何通过子选择*通过fluent nhibernate加入_Sql_Nhibernate_Fluent Nhibernate - Fatal编程技术网

Sql 如何通过子选择*通过fluent nhibernate加入

Sql 如何通过子选择*通过fluent nhibernate加入,sql,nhibernate,fluent-nhibernate,Sql,Nhibernate,Fluent Nhibernate,NH是否已经可以创建连接选择查询,如 Select * From table1 Join ( Select * From table2 ...? 为什么他不能 在我的任务中,我有一个简单的表: TABLE [Message]( [Id] [int] NOT NULL, [DocId] [int] NOT NULL, [RecipientId] [bigint] NOT NULL, [Text] [nvarchar](255) NULL, [ArrivalDate]

NH是否已经可以创建连接选择查询,如

 Select * From table1 Join ( Select * From table2 ...? 
为什么他不能

在我的任务中,我有一个简单的表:

TABLE [Message](
  [Id] [int] NOT NULL,  
  [DocId] [int] NOT NULL,
  [RecipientId] [bigint] NOT NULL,
  [Text] [nvarchar](255) NULL,
  [ArrivalDate] [date] NOT NULL
然后选择:

SELECT msg.*
FROM [Message] msg
JOIN( SELECT msgMaxForDoc.DocId, MAX(msgMaxForDoc.ArrivalDate) AS ArrivalDate
      FROM [Message] msgMaxForDoc
      GROUP BY msgMaxForDoc.DocId) docAndDate ON msg.DocId = docAndDate.DocId AND msg.ArrivalDate = docAndDate.ArrivalDate
WHERE msg.RecipientId = @UserId
完整任务听起来像:为用户选择所有消息。若由DocId表示的文档包含多条消息,则获取最新消息。结果,我必须为所有受UserId限制的DocId选择一条最新消息

我在这里发现了一个类似的问题: 但这并没有帮助,我没有任何指向其他平板电脑的链接DocId只是一个数字


在这里,但我不能将select分为两部分…

据我所知,使用NHibernate连接子查询是不可能的。但是,您可能可以使用WHERE EXISTS方法实现您的目标:

var dCriteria = DetachedCriteria.For<Message>("grouped")
.SetProjection(Projections.GroupProperty("grouped.DocId"))
.SetProjection(Projections.Max("grouped.ArrivalDate"))
.Add(Restrictions.EqProperty("msg.DocId", "grouped.DocId"))
.Add(Restrictions.EqProperty("msg.ArrivalDate", "grouped.ArrivalDate"))
.Add(Restrictions.Eq("grouped.RecipientId", @UserId));

var userMessages = Session.CreateCriteria<Message>("msg")
.Add(Subqueries.Exists(dCriteria)).List<Message>();