none
c# LINQ to Entities does not recognize the method 'Boolean RRS feed

  • Question

  •  How to  address Boolean method below. The value Online has to be set. The error I get is 
    "c# LINQ to Entities does not recognize the method 'Boolean" 
     
    foreach (var i in (from a in db.Color
    join i in db.ColorClothes
    on a.InstallationId equals i.InstallationId
    where a.Id == Id
    select
    new
    {
    ID= i.id,
    OnLine = Utilities.IsConnectionValid(i.InstallationId) ? true : false, I get the error right here
    }).ToList())

    pianoboyCoder

    Friday, November 3, 2017 11:01 PM

All replies

  • Probably this query is supposed to be executed on SQL Server, where your code that defines IsConnectionValid is not available.

    Give details about this function and consider replacing it with some expression that can be executed in SQL. If this is not possible, then execute a query that does not yet calculate OnLine, wich will be calculated later, something like this:

    foreach( var i in ( from a in db.Color
                        join i in db.ColorClothes
                        on a.InstallationId equals i.InstallationId
                        where a.Id == Id
                        select
                           new
                           {
                              ID = i.id,
                              InstallationId = i.InstallationId
                           } )
                       .ToList()
                       .Select( z =>
                           new
                           {
                              ID = z.ID,
                              OnLine = Utilities.IsConnectionValid(z.InstallationId)
                           } )
                        ) )



    Saturday, November 4, 2017 8:20 AM
  • Your utility function you may have to make new one should simply return the bollean and the projection trying to do it.

    Saturday, November 4, 2017 10:17 AM

  • Hi pianoboyCoder,

    thanks for posting here.

    For your case about ADO.NET Entity Framework and LINQ to Entities, I will move it to the ADO.NET Entity Framework and LINQ to Entities forum for getting suitable help.

    Your understanding and cooperation will be grateful.

    Best Regards,

    Yohann Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 6, 2017 2:43 AM
    Moderator