I would like to use the if statement below to calculate a StockCode for my product, but I am getting the error:
Cannot implicitly convert type 'TruckWcf.Models.StockItem' to 'bool'
Now I am a newbie in C# as well as EF6, so I am trying my best to understand what is going on here :P.
var qisg = new QuoteItemSectionGroup
{
SectionGroup = db.SectionGroups.Where(x => x.Name == "Longitudinals" && x.Section == TruckSection.Floor).First(),
StockItem = db.StockItems.Where(x => x.StockCode == "SCH113").First() ? quoteItem.Chassis.Longitudinal : quoteItem.BodyType.Longitudinal, // <<-- Here lies my error
Quantity = 2,
Length = globals.FloorCalculatedLength
};
Can someone please advise me how to fix this small, yet simple problem. Thank you!
As explained to you in your previous question on this topic, the ternary operator takes the form:
You however are doing:
In this case
db.StockItems.Where(x => x.StockCode == "SCH113").First()doesn't return a boolean. So you need to fix this expression, presumably by comparing it with some other value.