I have a table with the following columns
inspection_dt,
contact_dt,
description,
product_mod,
product_desc,
contact_nm,
history_id,
inspect_id,
history_type,
incident_product_id,
contact_history_id
I would to use LINQ to query a generic list of rows from this table. The twist is that I want the smallest (MIN) value of history_id -- and mimic this SQL query.
SELECT DISTINCT
inspection_dt,
contact_dt,
description,
product_mod,
product_desc,
contact_nm,
MIN(history_id) AS history_id,
inspect_id,
history_type,
incident_product_id,
contact_history_id
FROM
myTable
GROUP BY
inspection_dt,
contact_dt,
description,
product_mod,
product_desc,
contact_nm,
inspect_id,
history_type,
incident_product_id,
contact_history_id
I've tried snippets like
var searchData = items
.GroupBy(i => new { i.history_id })
.Select(g => new { history = g.Min() })
.Distinct();
But still get all messed up
I get stuck using functions like MIN, MAX, etc, and grouping in LINQ and would appreciate any help I can get.
Thanks,