0

My Database Table structure:

Schema  Property  Type

For different 'Schema' values I have same 'Property' and 'Type' values.

My linq query:

IEnumerable<CModel> model = db.dbModels.AsEnumerable().Select(o => new CModel { CName = "XXX", PName = o.Property, PType = o.Type }).Distinct().ToList();

What I'm trying to do is get distinct 'Property' and 'Type' values but the query is giving me duplicate values.

Thanks

2
  • 1
    What are the date types of Property and Type? If they are simple types like string or int this query should produce distinct results. And what's the use of this AsEnumerable()? Commented Oct 23, 2014 at 6:51
  • @GertArnold data types are string, Removing ASEnumerable solved the problem..Thanks Commented Oct 23, 2014 at 7:05

1 Answer 1

1

You can group them:

IEnumerable<CModel> model = db.dbModels.AsEnumerable()
                            .GroupBy(x => new { x.Property, x.Type })
                            .Select(x => new CModel 
                                        { CName = "XXX", 
                                          PName = x.Property, 
                                          PType = x.Type }).ToList();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.