I've been struggling with this for a few days now and I'm stumped. I'm hoping that someone can provide an alternate suggestion. Basically, I'm reading data from excel using LinqToExcel. But I want to exclude all rows with a "Rating" of "NR". Here's a sample of my data:
CompanyName Rating SalesMan
Apple 2 Steve
Google NR Steve
Microsoft 3 John
Dell 1 Steve
Pepsi 3 John
I just want to find all companies that belong to Steve but doesn't have a rating of "NR". My final list should be:
CompanyName SalesMan
Apple Steve
Dell Steve
I've tried the following code but it doesn't work:
1)
var masterList = masterDataXL.Worksheet("data_all").Where(d => !d["Rating"].Equals("NR"));
2)
var masterList = masterDataXL.Worksheet("data_all")
.Where(m =>
!m["Rating"].Equals("NR")
&&
m["SalesMan"].ToString().Contains(resAnLastName)) // check for last name
.Select(m => new ResAnTicksDataClass
{
Company = m["CompanyName"],
Rating = m["Rating"],
Seller = m["SalesMan"]
}).AsEnumerable();
3) Created a property for Rating and did the following:
var masterList = masterDataXL.Worksheet("data_all")
.Where(m =>
m["Analyst"].ToString().Contains(resAnLastName)) // check for last name
.Select(m => new ResAnTicksDataClass
{
Company = m["CompanyName"],
Rating = m["Rating"],
Seller = m["SalesMan"]
}).AsEnumerable();
var dataList = (from m in masterList
where m.Rating != "NR"
select new ResAnTicksDataClass
{
ResAnName = m.ResAnName,
DescrTick = m.DescrTick
}).AsEnumerable();
I'm open to any other suggestions that you might have because I'm completely stumped. Thank you so much in advance.