3
Answers

LINQ to Entities query and Distinct on GUID

Maik Brauer

Maik Brauer

13y
5.5k
1
Hi all,

when I use the LINQ to Entities and then a Distinct to get unique Guids, I'm getting all GUIDs.

DB-Entry 1: {b3f86f18-f661-4511-a8b5-f85aa8e41b29}
DB-Entry 2: {b3f86f18-f661-4511-a8b5-f85aa8e41b29}
DB-Entry 3: {7078d941-0906-4a1b-9a27-85cfc9cf382b}
DB-Entry 4: {7387d57e-6ac5-4b3b-b7f5-833383530bb6}

using (OrderTableEntities msgcontext = new OrderTableEntities())
  {
  try
  {

  var Query = from c in msgcontext.tbl_Order
  select c.OrderGuid;

  var distinctGuids = Query.Distinct();
  } catch
  {

  }
  }

After Execution of this code-part, all 4 rows are queried. Basically I would have expected to get just
3 Entries back. What could cause this issue, that it is not possible to get the DISTINCT Guid?

Thanks.
Answers (3)