【发布时间】:2012-07-27 21:42:16
【问题描述】:
我正在尝试根据 distinct 过滤记录。我使用了以下代码
List<BALHotelList> searchresult = (from a in bh
join b in hr on a.HotelCode equals b.hotelCode
orderby a.HotelName
select new BALHotelList
{
HotelCode = a.HotelCode,
ImageURL_Text = a.ImageURL_Text,
HotelName = a.HotelName,
StarRating = a.StarRating,
HotelAddress = a.HotelAddress,
Destination = a.Destination,
Country = a.Country,
HotelInfo = a.HotelInfo,
Latitude = a.Latitude,
Longitude = a.Longitude,
HotelArea=a.HotelArea,
totalPrice = b.totalPrice,
totalPriceSpecified = b.totalPriceSpecified,
totalSalePrice = b.totalSalePrice,
totalSalePriceSpecified = b.totalSalePriceSpecified,
rooms = b.rooms,
boardType = b.boardType
}).ToList();
var uniqueArea =searchresult.Select(m => m.HotelArea).Distinct();
rptHotelArea.DataSource = uniqueArea;
rptHotelArea.DataBind();
但它没有在数据源中找到 HotelArea。
但是当我调试它时,它会显示uniqueArea中的所有不同值
错误如下:
DataBinding: 'System.String' does not contain a property with the name 'HotelArea'.
已编辑
这里是转发器 HTML
<asp:Repeater ID="rptHotelArea" runat="server">
<ItemTemplate>
<div class="sub-part1">
<a href="#"><%#Eval("HotelArea")%></a></div>
</ItemTemplate>
</asp:Repeater>
【问题讨论】:
-
请看一下这个问题的答案:stackoverflow.com/questions/5011617/….
-
@Serge +1 它的作品。在不同情况下是否将 null 视为唯一的另一件事
-
是的,我想跳过空值
-
var uniqueArea =searchresult.Select(m => m.HotelArea).Where(m => m != null).Distinct();
-
那么空字符串呢?请张贴您的 cmets 作为答案,以便我接受。它比乔恩答案更接近