开发者

How to select single record with Linq?

i have this table

**ID           CityCode             Price**

1             ABB                  100
2             CAB                  160
3             CAB                  340
4             TRE                  800
5             ABB                  770
6             TRE                  900
7             ABB                  500

I want write down a query(linq) which will return the following result as show the code below

CityCo开发者_如何学Gode

   ABB
   CAB
   TRE

i want select a list with only the CityCode without duplicate record, How can i do it with linq to sql ?

Thanks so much for your attention,

have a good time, Cheers


It sounds like you want Distinct()

var cityCodes = cities.Select(x => x.CityCode).Distinct();

That's not the same as retrieving a single record (as per your title) though. If this isn't what you're after, please give us more information.


Try using .Distinct():

var city = (from ci in dc.citieis select ci.CityCode).Distinct();

I hope this is what you're looking for; please try to make your question more explainatory. For more on LINQ you can checkout my blog here : linqtoSQL

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜