Hello, I write a query, like
then I transform it into:
and then I try to write in fluent variant, but I do not know, what to use instead of let word.
It seems to me, that I can use group join, but I have one to one relation between offer and parcel objects. And this way I think, it is not optimal to use here.
So... I need help.
C#:
foreach (var deal in dealCollection)
{
foreach (var offer in deal.Offers)
{
if (offer.ClientId == testCurrentUserId)
{
if (parcelCollection.Any(parcelElement=> parcelElement.OfferId==offer.Id))
{
var parcel = parcelCollection.First(parcelElement => parcelElement.OfferId == offer.Id);
var dealOfferParcelDto = new DealOfferParcelDto();
dealOfferParcelDto.DealIdentificationNumber = deal.Id;
dealOfferParcelDto.DealShifterId = deal.ShifterId;
dealOfferParcelDto.DealStatus = deal.DealStatus;
dealOfferParcelDto.DealDescription = deal.Description;
dealOfferParcelDto.DealBaggageType = deal.BaggageType;
dealOfferParcelDto.DealTransport = deal.Transport;
dealOfferParcelDto.DealLocation = deal.Location;
dealOfferParcelDto.DealStartDate = deal.StartDate;
dealOfferParcelDto.DealEndDate = deal.EndDate;
dealOfferParcelDto.DealLocationFrom = deal.LocationFrom;
//dealOfferParcelDto.DealLocationTo = deal.LocationTo;
//dealOfferParcelDto.DealAddressFrom = deal.AddressFrom;
//dealOfferParcelDto.DealAddressTo = deal.AddressTo;
dealOfferParcelDto.DealLastModified = deal.LastModified;
//dealOfferParcelDto.DealWayPointCollection = deal.WayPointCollection;
dealOfferParcelDto.DealTransportationPrice = deal.TransportationPrice;
dealOfferParcelDto.OfferIdentificationNumber = offer.Id;
dealOfferParcelDto.OfferStatus = offer.OfferStatus;
dealOfferParcelDto.OfferWhoCreator = offer.WhoCreator;
dealOfferParcelDto.OfferSum = offer.OfferSum;
dealOfferParcelDto.OfferClientId = offer.ClientId;
dealOfferParcelDto.OfferDescription = offer.Description;
dealOfferParcelDto.OfferLastModified = offer.LastModified;
dealOfferParcelDto.ParcelClientId = parcel.ClientId;
dealOfferParcelDto.ParcelId = parcel.Id;
dealOfferParcelDto.ParcelOfferId = parcel.OfferId;
//dealOfferParcelDto.ParcelAddressFrom = parcel.AddressFrom;
//dealOfferParcelDto.ParcelAddressTo = parcel.AddressTo;
//dealOfferParcelDto.ParcelLocationFrom = parcel.LocationFrom;
//dealOfferParcelDto.ParcelLocationTo = parcel.LocationTo;
dealOfferParcelDto.ParcelDepartureDateTime = parcel.DepartureDateTime;
dealOfferParcelDto.ParcelBaggageTypes = parcel.BaggageTypes;
dealOfferParcelDto.ParcelSum = parcel.ParcelSum;
dealOfferParcelDto.ParcelDescription = parcel.ParcelDescription;
dealOfferParcelDto.ParcelLastModified = parcel.LastModified;
collectionDealOfferParcel.Add(dealOfferParcelDto);
}
}
}
}
then I transform it into:
C#:
collectionDealOfferParcel = (from deal in dealCollection
from offer in deal.Offers
where offer.ClientId == testCurrentUserId && parcelCollection.Any(parcelElement => parcelElement.OfferId == offer.Id)
let parcel = parcelCollection.First(parcelElement => parcelElement.OfferId == offer.Id)
select new DealOfferParcelDto
{
DealIdentificationNumber = deal.Id,
DealShifterId = deal.ShifterId,
DealStatus = deal.DealStatus,
DealDescription = deal.Description,
DealBaggageType = deal.BaggageType,
DealTransport = deal.Transport,
DealStartDate = deal.StartDate,
DealEndDate = deal.EndDate,
DealLastModified = deal.LastModified,
DealTransportationPrice = deal.TransportationPrice,
OfferIdentificationNumber = offer.Id,
OfferStatus = offer.OfferStatus,
OfferWhoCreator = offer.WhoCreator,
OfferSum = offer.OfferSum,
OfferClientId = offer.ClientId,
OfferDescription = offer.Description,
OfferLastModified = offer.LastModified,
ParcelClientId = parcel.ClientId,
ParcelId = parcel.Id,
ParcelOfferId = parcel.OfferId,
ParcelDepartureDateTime = parcel.DepartureDateTime,
ParcelBaggageTypes = parcel.BaggageTypes,
ParcelSum = parcel.ParcelSum,
ParcelDescription = parcel.ParcelDescription,
ParcelLastModified = parcel.LastModified
}).ToList();
and then I try to write in fluent variant, but I do not know, what to use instead of let word.
C#:
var collection =
dealCollection
.SelectMany(deal => deal.Offers
.Where(offer => offer.ClientId
== testCurrentUserId
&& parcelCollection.Any(parcelElement =>
parcelElement.OfferId == offer.Id)));
It seems to me, that I can use group join, but I have one to one relation between offer and parcel objects. And this way I think, it is not optimal to use here.
So... I need help.