Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3212364
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:49:51+00:00 2026-05-17T14:49:51+00:00

I’m trying to get this LINQ to work but fails with the error. Cannot

  • 0

I’m trying to get this LINQ to work but fails with the error.

Cannot convert lambda expression to type ‘System.Collections.Generic.IEqualityComparer’ because it is not a delegate type

Basically I have IEnumerable<DataRow> and I’m trying to group the data, as in:

string sql = @"SELECT [t0].[Contact_Account] AS [Contact], [t0].[Work_Phone] AS [WorkPhone], [t0].[SR_NUM] AS [SRNum] ";
sql += "FROM [Base_SR] AS [t0] ";
sql += "WHERE ([t0].[Country] = 'USA') AND (NOT ([t0].[Work_Phone] LIKE '+%')) ";
sql += "AND ([t0].[Product] = 'SP3D') AND (DATEPART(Year, [t0].[DateOpened]) = {0})";

sql = String.Format(sql, curYear);

var sqlCmd  = new SqlCommand(sql, new SqlConnection(connectionString));
var adapter = new SqlDataAdapter(sqlCmd);
var dataSet = new DataSet();
adapter.Fill(dataSet);
var siebelRows = dataSet.Tables[0].AsEnumerable();

return siebelRows.GroupBy(sr => new { AreaCode = sr.Field<string>("WorkPhone").Substring(0, 3), 
          Contact = sr.Field<string>("Contact") },
     (key, lst) => new Customer 
     {
                        Id = Guid.NewGuid(),
      AreaCode = key.AreaCode,
      CustAccount = key.Contact,
      FirstPhoneNo = lst.First().Field<string>("WorkPhone").Substring(0, 10),
      FirstSRNum= lst.First().Field<string>("SRNum"),
      SRCount = lst.Count()
     })
     .Take(5);

Any thoughts ?

DigEmAll’s suggestion helped (thanks) and I had to do this:

public class GroupKey
{
    public string AreaCode { get; set; }
    public string Contact { get; set; }
}

And then change the LINQ to this GroupBy key:

GroupBy<DataRow, GroupKey, IEnumerable<Customer>>

return siebelRows.GroupBy<DataRow, GroupKey, IEnumerable<Customer>>(sr => new GroupKey
{
    Contact = sr.Field<string>("Contact"),
    AreaCode = sr.Field<string>("WorkPhone").Substring(0, 3)
},
    (key, lst) => new Customer
        {
            Id = Guid.NewGuid(),
            AreaCode = key.AreaCode,
            CustAccount = key.Contact,
            FirstPhoneNo = lst.First().Field<string>("WorkPhone").Substring(0, 10),
            FirstSRNum = lst.First().Field<string>("SRNum"),
            SRCount = lst.Count()
        }).OrderByDescending(c => c.SRCount)
        .Take(5);

Don’t like creating a concrete type for the key…any way around this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T14:49:51+00:00Added an answer on May 17, 2026 at 2:49 pm

    I think your problem is in the Field<T> in your Anonymous type definition.

    You should specify the type T (cannot be inferred from the usage), then compiler will recognize the correct GroupBy overload.


    EDIT according to OP changes:

    You don’t need to create a concrete type, just specify explicitly the right T in Field<T>(...), so in your code:

    sr => new { AreaCode = sr.Field<string>("WorkPhone").Substring(0, 3), 
                Contact = sr.Field<string>("Contact") }
    

    EDIT 2:

    OK, I’ve edited your question because actually your <...> were hidden (don’t use <code><pre> manually, just click on the appropriate button 😉 ).

    Anyway, your last code has an error in the GroupBy types specification:

    is not <DataRow, GroupKey, IEnumerable<Customer>>,

    but <DataRow, GroupKey, Customer>

    because you just have to specify the inner Type of the returned IEnumerable.

    Then, I’ve tried your last code, and also removing the concrete type GroupKey (and obviously removing the GroupBy types specification) it is perfectly valid:

    var customers = siebelRows.GroupBy( 
        sr => new 
        {
            Contact = sr.Field<string>("Contact"),
            AreaCode = sr.Field<string>("WorkPhone").Substring(0, 3)
        },
        (key, lst) => new Customer
        {
            Id = Guid.NewGuid(),
            AreaCode = key.AreaCode,
            CustAccount = key.Contact,
            FirstPhoneNo = lst.First().Field<string>("WorkPhone").Substring(0, 10),
            FirstSRNum = lst.First().Field<string>("SRNum"),
            SRCount = lst.Count()
        })
        .OrderByDescending(c => c.SRCount)
        .Take(5);
    return customers;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.