0

I have class Contact:

 public class Contact
    {
    public string Function { get; set; };

    public string Civility { get; set; }

    public string FirstName { get; set; }


    public List<Certification> Certifications { get; set; } = new List<Certification>();

}

My query logic is as follows:

List<Contact> contacts
                  = await Context.Database
                                         .SqlQuery<Contact>("[dbo].[Contact] @codes,@Sprache",
                                         parameters).ToListAsync();

How to use .selectMany fot have olny names of functions of this class?

Elddif
  • 71
  • 1
  • 10
  • How many records are there in your db? If there are 15, why do you want 9? – CodingYoshi Aug 06 '18 at 15:40
  • I have 15 but there are duplicates (Sylvain x2, Clémence x3) ... – Elddif Aug 06 '18 at 15:43
  • 1
    Thats because one is `Certification Officer` and the other is `Sales Officer`. They are completely different records with different ids. If you just want their names, then change your query and only get `distinct` last name. – CodingYoshi Aug 06 '18 at 15:53
  • no I need 1 list of FunctionsOOP and 1 list of pk_PrestaOOP. For example : for Stéphanie I need 1 lastName, 1 firstNam, 1 list of Function = { "Certification Officer","Sales Officer") and 1 list of pk_PrestaOOP = {"6DD....", "F6C...","EB6..."}, 1 email and 1 n° tel – Elddif Aug 06 '18 at 16:00
  • 1
    You data model should be normalized. One contact should be related to multiple function records. Until you do that you'll never be able to get a list of distinct contacts easily. It'll even be harder to get data related to one contact, for example all `Certifications` one contact has. – Gert Arnold Aug 06 '18 at 16:03
  • You could use `GroupBy` to merge the duplicate records, but it is a bad idea to create a new `Contact` that does not match a record in the database, so you would have to return a new class or an anonymous object. – NetMage Aug 06 '18 at 17:44

1 Answers1

0

If you want distinct objects why not use Distinct(). From my understand Select Many will flatten (aka reduce the nested collections) a collection. Check this question out