I need to get the count of two fields using NHibernate query. Given the sample data of historicalList below, the result should be 1 Project assign to 2 Nodes. How to get the result using the Nhibernate query. Please see below my approach, Anyone can help to rewrite the code?
//Sample Data
var nodelist= new List<Node>{
new Node{1, "Node1"},
new Node{2, "Node2"},
new Node{3, "Node3"},
new Node{4, "Node4"},
new Node{5, "Node5"},
}
var projectlist= new List<Project>{
new Project{1, "Project1"},
new Project{2, "Project2"},
new Project{3, "Project3"},
new Project{4, "Project4"},
new Project{5, "Project5"},
}
var historicalList= new List<Historical>
{
new Historical{1, 1,1}
new Historical{1, 1,2}
}
public class Node
{
public virtual long ID { get; set; }
public virtual string NodeName { get; set; }
}
public class Project
{
public virtual long ID { get; set; }
public virtual string ProjectName { get; set; }
}
public Historical
{
public virtual long ID { get; set; }
public virtual string ProjectID { get; set; }
public virtual string NodeID { get; set; }
}
//sample code
using (var session = OpenSession())
{
var historical= session.Query<Historical>()
.Where(
x => nodeIds.Contains(x.Node.ID));
var nodeCount = historical.Select(y => y.Node.ID).Distinct().Count();
var projectCount = historical.Select(y => y.Project.ID).Distinct().Count();
}