Domanda

I have requirement in which i just want to return List of Unique Vendor ID based on Service Status, Done/No;

Select Distinct(vendorid) FROM DC_System_Assets where ServiceStatus='Done'

I tried to write like that but it's getting error.

public List<int> AutoScheduleMails()
{
    var v = db.DC_System_Assets.Select(f => f.VendorId).Distinct().Where(p => p.ServiceStatus == "Done").ToList();
}

'System.Nullable' does not contain a definition for 'ServiceStatus' and no extension method 'ServiceStatus' accepting a first argument of type 'System.Nullable' could be found (are you missing a using directive or an assembly reference?)

È stato utile?

Soluzione

You are selecting a list of VendorIds, and then trying to filter by ServiceStatus (which is not a property of VendorId). Try...

var v = db.DC_System_Assets
            .Where(a => a.ServiceStatus == "Done")
            .Select(a => a.VendorId)
            .Distinct()
            .ToList();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top