Operator '&&' cannot be applied to operands of type 'lambda expression' and 'lambda expression

c# entity-framework lambda

Question

I developed my method as follows because I want to retrieve all records that include IP or MAC addresses or if any of them are null.

public IQueryable<Technology> AdvanceSearch(string ip = null, string mac = null, int techtype) 
        {
            var relatedresourcesID = entities.NetworkInfoes
                .Where((a => String.IsNullOrEmpty(ip) || a.IPADDRESS.StartsWith(ip)))
                .Where(a2 => String.IsNullOrEmpty(mac) || a2.MACADDRESS.StartsWith(mac)).Select(a3=>a3.WORKSTATIONID);
//code goes here

However, I'm not clear how EF will elevate the. will it apply the second; where. just after using the first where(). the where clause

How can I apply all the checks to be inside one, is my second query. Where()??

I've attempted to rewrite my approach as follows:

var relatedresourcesID = entities.NetworkInfoes
                .Where((a => String.IsNullOrEmpty(ip) || a.IPADDRESS.StartsWith(ip)) && (a2 => String.IsNullOrEmpty(mac) || a2.MACADDRESS.StartsWith(mac)) )
                .Select(a3=>a3.WORKSTATIONID);

but I will encounter the subsequent error:

Error 18 Operator '&&' cannot be applied to operands of type 'lambda expression' and 'lambda expression' C:\Users\Administrator\documents\visual studio 2012\Projects\TMS\TMS\Models\Repository.cs 914 24 TMS

1
5
10/25/2013 11:23:20 PM

Accepted Answer

ZZZ_tmp
9
10/25/2013 11:36:39 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow