-
-
Notifications
You must be signed in to change notification settings - Fork 239
Open
Description
Bug description
I encountered several errors while querying on list property that was projected into string
Example class
public enum TestEnum
{
T1, T2
}
public class TestClass
{
public TestEnum P1 { get; set; }
public IEnumerable<TestEnum> P2 { get; set; }
}Examples
List:
var list = new List<TestClass> {
new TestClass { P1 = TestEnum.T1, P2 = [TestEnum.T1, TestEnum.T2] },
new TestClass { P1 = TestEnum.T2, P2 = [TestEnum.T2] }
};Works:
var result = list.AsQueryable().Where("P1==\"T1\"");Throws No generic method 'Contains' on type 'System.Linq.Enumerable
var result = list.AsQueryable().Where("P2.Contains(\"T1\")");Creates query, works on list in memory nad works without where on EF dbSet but on EF dbSet throws "expression could not be translated" with Additional information: Translation of method 'object.ToString' failed
var result3 = list.AsQueryable().Select(_ =>
new {
_.P1,
P2 = _.P2.Select(__ => __.ToString())
}).Where("P2.Contains(\"T1\")");What I actually want to do on ef dbSet and it works without where but with where it just throws "expression could not be translated"
var result4 = list.AsQueryable().Select(_ =>
new {
_.P1,
P2 = string.Join("", _.P2.Select(__ => __.ToString()))
}).Where("P2.Contains(\"T1\")");EF Core version
8.0.12
Database provider
tested in Oracle.EntityFrameworkCore 8.23.60
Target framework
.Net 8
Operating system
Windows 10
IDE
Visual Studio 2022 17.11.5
Metadata
Metadata
Assignees
Labels
No labels