System.Linq.Dynamic.Core icon indicating copy to clipboard operation
System.Linq.Dynamic.Core copied to clipboard

Join problem with inherited entities

Open Ibehem opened this issue 3 years ago • 4 comments

  1. Description When I try to join on a descendant of a class I got an error: x and y are incompatible

While the same in Strongly typed Line works.

  1. Fiddle or Project

Based on the pets and person project: https://dotnetfiddle.net/eEYaoU

Here is a sample: I have a simple hierarchy:

public class Samples
{
	public int Id { get; set; }
	public string Name { get; set; }
	public List<Result> Results { get; set; } 
}

public class SoilSamples : Samples
{
	public int Deep { get; set; }
}


public class Result
{
	public int Id { get; set; }
	public int Value { get; set; }
	public Samples Sample { get; set; }
}

Ibehem avatar Jul 22 '22 14:07 Ibehem

Hello @Ibehem,

Thanks for creating this issue.

I did find the issue and I've corrected it. Do you want to test a preview version?

Note that your join is not correct, it should be something like this:

// Arrange
var magnus = new Person { Name = "Hedlund, Magnus" };
var terry = new Person { Name = "Adams, Terry" };
var charlotte = new Person { Name = "Weiss, Charlotte" };

var barley = new Pet { Name = "Barley", Owner = terry };
var boots = new Pet { Name = "Boots", Owner = terry };
var whiskers = new Pet { Name = "Whiskers", Owner = charlotte };
var daisy = new SpecialPet { Name = "Daisy", Owner = magnus, IsSpecial = true };

var people = new List<Person> { magnus, terry, charlotte };
var pets = new List<Pet> { barley, boots, whiskers, daisy };

// Act
var realQuery = people.AsQueryable()
	.Join(
		pets,
		person => person,
		pet => pet.Owner,
		(person, pet) => new { OwnerName = person.Name, Pet = pet.Name });
var realResult = realQuery.ToList();

var dynamicQuery = people.AsQueryable()
	.Join(
		pets,
		"it",
		"Owner",
		"new(outer.Name as OwnerName, inner.Name as Pet)");
var dynamicResult = dynamicQuery.ToDynamicList();

realResult.Should().BeEquivalentTo(dynamicResult);

StefH avatar Aug 05 '22 11:08 StefH

Hello Stef, Yes I would love to test a preview version ! And thank you very much for solving this so quickly! (Ibehem is my personal account), any of them would be fine

EfrSyn avatar Aug 05 '22 11:08 EfrSyn

A preview (preview-02) can be downloaded from MyGet: https://www.myget.org/F/system-linq-dynamic-core/api/v3/index.json

See this link on how to use MyGet: https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

CC: @EfrSyn / @Ibehem

StefH avatar Aug 05 '22 11:08 StefH

Hello @EfrSyn / @Ibehem,

Did you have time to verify if this was solved using that preview version?

StefH avatar Sep 09 '22 05:09 StefH

Hello @EfrSyn / @Ibehem,

Did you have time to verify if this was solved using that preview version?

StefH avatar Oct 20 '22 16:10 StefH

Hello @EfrSyn / @Ibehem,

Did you have time to verify if this was solved using that preview version?

StefH avatar Oct 28 '22 15:10 StefH

Hello @EfrSyn / @Ibehem,

Did you have time to verify if this was solved using that preview version?

StefH avatar Nov 05 '22 12:11 StefH

Hello @EfrSyn / @Ibehem,

Did you have time to verify if this was solved using that preview version?

StefH avatar Nov 24 '22 08:11 StefH

PR merged

StefH avatar Nov 26 '22 09:11 StefH