linq-to-entities

Remove duplicate records using LINQ [duplicate]

瘦欲@ 提交于 2021-01-01 03:34:28
问题 This question already has answers here : LINQ: Distinct values (7 answers) Closed 5 years ago . I want to use linq to object to remove duplicate records. I want that final list will contain unique records with the latest Date. I have the following list AId BId C(date) **1 2 24/5/2015** 3 6 24/5/2015 **1 2 23/5/2015** (Need To Remove) I want to remove record 3. Any Advise? 回答1: You can use GroupBy and then Select with OrderByDescending to order the dates. public class Item { public int Aid

Linq-To-Entities using method to select new object

早过忘川 提交于 2020-12-09 08:05:50
问题 I try to use the same select query multiple times in my application. For example I have this select statement: _db.tbl_itembundlecontents .Select(z => new SingleItemDTO { amount = z.amount, id = z.id, position = z.position, contentType = new BasicMaterialDTO { id = z.tbl_items.id, img = z.tbl_items.tbl_material.img, name = z.tbl_items.tbl_material.name, namekey = z.tbl_items.tbl_material.namekey, info = z.tbl_items.tbl_material.info, weight = z.tbl_items.tbl_material.weight } }); but i also

Linq-To-Entities using method to select new object

生来就可爱ヽ(ⅴ<●) 提交于 2020-12-09 08:03:32
问题 I try to use the same select query multiple times in my application. For example I have this select statement: _db.tbl_itembundlecontents .Select(z => new SingleItemDTO { amount = z.amount, id = z.id, position = z.position, contentType = new BasicMaterialDTO { id = z.tbl_items.id, img = z.tbl_items.tbl_material.img, name = z.tbl_items.tbl_material.name, namekey = z.tbl_items.tbl_material.namekey, info = z.tbl_items.tbl_material.info, weight = z.tbl_items.tbl_material.weight } }); but i also