"Expression type 'NhDistinctExpression' is not supported by this SelectClauseVisitor." - 使用查询语法
"Expression type 'NhDistinctExpression' is not supported by this SelectClauseVisitor." - with Query Syntax
给定以下表达式,我如何才能获得不同的场地列表,而不会出现令人讨厌的 "Expression type 'NhDistinctExpression' is not supported by this SelectClauseVisitor." 错误?
public Dictionary<int, string> GetScheduledVenuesFuture()
{
var venues = from v in _sp.CurrentSessionOn(DatabaseName.MyDB).Query<Venue>()
join s in _sp.CurrentSessionOn(DatabaseName.MyDB).Query<ScheduledClass>()
on v.VenueId equals s.Venue.VenueId
where s.CourseDate >= _cac.Now
&& s.Closed == false
&& s.Canceled == false
select new
{
v.VenueId,
v.Name
};
return venues.ToDictionary(v => v.VenueId, v => v.Name);
}
我试过设置
return venues.ToDictionary(v => v.VenueId, v => v.Name);
通过以下方式区分:
return venues.Distinct().ToDictionary(v => v.VenueId, v => v.Name);
但这会引发错误。我还尝试将整个查询语法语句包围在括号中,并在其末尾放置一个 .Distinct() ,但这也导致了同样的错误。
我最终以另一种方式解决了这个问题:
public class ScheduledVenueDTO
{
public int VenueId { get; set; }
public string Name { get; set; }
}
public Dictionary<int, string> GetScheduledVenuesFuture()
{
var venues = from v in _sp.CurrentSessionOn(DatabaseName.SMS).Query<Venue>()
join s in _sp.CurrentSessionOn(DatabaseName.SMS).Query<ScheduledClass>()
on v.VenueId equals s.Venue.VenueId
where s.CourseDate >= _cac.Now
&& s.Closed == false
&& s.Canceled == false
select new
{
v.VenueId,
v.Name
};
var svd = venues
.GroupBy(v => new { v.VenueId, v.Name})
.Select(v => new ScheduledVenueDTO() {
VenueId = v.Key.VenueId,
Name = v.Key.Name
});
return svd.ToDictionary(v => v.VenueId, v => v.Name);
}
我只是创建了一个新的 DTO,并使用 groupBy 为该 DTO 注入了唯一不同的场所。
给定以下表达式,我如何才能获得不同的场地列表,而不会出现令人讨厌的 "Expression type 'NhDistinctExpression' is not supported by this SelectClauseVisitor." 错误?
public Dictionary<int, string> GetScheduledVenuesFuture()
{
var venues = from v in _sp.CurrentSessionOn(DatabaseName.MyDB).Query<Venue>()
join s in _sp.CurrentSessionOn(DatabaseName.MyDB).Query<ScheduledClass>()
on v.VenueId equals s.Venue.VenueId
where s.CourseDate >= _cac.Now
&& s.Closed == false
&& s.Canceled == false
select new
{
v.VenueId,
v.Name
};
return venues.ToDictionary(v => v.VenueId, v => v.Name);
}
我试过设置
return venues.ToDictionary(v => v.VenueId, v => v.Name);
通过以下方式区分:
return venues.Distinct().ToDictionary(v => v.VenueId, v => v.Name);
但这会引发错误。我还尝试将整个查询语法语句包围在括号中,并在其末尾放置一个 .Distinct() ,但这也导致了同样的错误。
我最终以另一种方式解决了这个问题:
public class ScheduledVenueDTO
{
public int VenueId { get; set; }
public string Name { get; set; }
}
public Dictionary<int, string> GetScheduledVenuesFuture()
{
var venues = from v in _sp.CurrentSessionOn(DatabaseName.SMS).Query<Venue>()
join s in _sp.CurrentSessionOn(DatabaseName.SMS).Query<ScheduledClass>()
on v.VenueId equals s.Venue.VenueId
where s.CourseDate >= _cac.Now
&& s.Closed == false
&& s.Canceled == false
select new
{
v.VenueId,
v.Name
};
var svd = venues
.GroupBy(v => new { v.VenueId, v.Name})
.Select(v => new ScheduledVenueDTO() {
VenueId = v.Key.VenueId,
Name = v.Key.Name
});
return svd.ToDictionary(v => v.VenueId, v => v.Name);
}
我只是创建了一个新的 DTO,并使用 groupBy 为该 DTO 注入了唯一不同的场所。