Ich habe eine Abfrage (in LINQPad Entwicklung):Linq zu Entitäten Left Outer Join/Unterabfrage?
DateTime currentDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
DateTime previousMonth = currentDate.AddMonths(-1);
DateTime previousMonthForAveragePrices = currentDate.AddMonths(-2);
var help = from cd in CostDrivers.OfType<Commodity>()
where cd.isActive == true &&
cd.arePricesCalculatedAverage == false
from cp in cd.CostDriverPrices where cp.priceDate
== currentDate
select new {cd.costDriverID, cd.costDriverName, cd.isUpdatedMonthly, cd.arePricesCalculatedAverage,
cp.costDriverPriceID, priceDate = cp.priceDate,
cp.price, previousPriceDate = from cpc in cd.CostDriverPrices where cpc.priceDate == previousMonth
select new {previousPrice = cpc.price, previousPriceDate = cpc.priceDate}};
help.Dump();
Was ich tun muss ist, alle costDrivers zurückzugeben, unabhängig davon, ob ein Preisdatensatz am angegebenen Datum existiert (currentDate). Ich sollte darauf hinweisen, dass es einen Versuch einer Unterabfrage gibt, um einen weiteren Preisrekord für einen aktuellen Monat zu erhalten. Ich habe es versucht || null usw. nicht gehen. Dies ist linq für Entitäten. Die Abfrage selbst funktioniert .. es wird nur Ergebnis zurückgeben, wo es einen Preis gibt. Vielen Dank!
danke.