I Have Two Tables: Properties,Rentals
Which have couple similar properties like:AreaInSquareMeters,RentalPrice, etc.. I have DTO to which I want to project them and then union them in a whole. But if I map the collections to the DTO then exception raises:
The 'Distinct' operation cannot be applied to the collection ResultType of the specified argument.Parameter name: argument
That's a little code which raise the exception
var properties = Context.Properties.Select(property => new PropertyInfoDTO
{
Id = property.Id,
PropertyName = property.PropertyName,
SellingPrice = property.SellingPrice,
RentalPrice = property.RentalPrice,
Images = property.Images.Select(image => new PropertyImagesInfoDTO
{
ImagePath = image.ImagePath,
ImageRatio = image.ImageRatio
}).ToList(),
other properties mapped here
}
Then:
var rentals = Context.Properties.Select(property => new PropertyInfoDTO
{
Id = property.Id,
PropertyName = property.Property.PropertyName,
SellingPrice = property.Property.SellingPrice,
RentalPrice = property.RentalPrice,
Images = property.Property.Images.Select(image => new PropertyImagesInfoDTO
{
ImagePath = image.ImagePath,
ImageRatio = image.ImageRatio
}).ToList(),
other properties mapped here
}
and I want to make the as a whole:
properties = properties.Union(rentals);
Everything is ok till I make a query to the DB and try to materialize the query Any suggestions of how to Cast both to Some DTO and Aggregate them ?
var rentals = Context.Rentals
?