-
-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot compare 'Object' type #451
Comments
@justinushermawan As a workaround, you could do the following: var result = queryable.Where("Values[1].Equals(\"Yeremia\") || Values[2].Equals(24)").ToList(); |
Thank you. Yes, I think it would be possible to call the |
Could this issue be fixed by checking if there is an operator overload for |
I bumped into this as well. Here is my use-case: using System;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Linq.Expressions;
using System.Collections.Generic;
internal class Program
{
private class Person
{
// Deliberately typing these as `object` to illustrate the issue
public object Id { get; set; } = Guid.NewGuid();
public object Name { get; set; }
public object Age => Convert.ToInt32(Math.Floor((DateTime.Today.Month - DateOfBirth.Month + 12 * DateTime.Today.Year - 12 * DateOfBirth.Year) / 12d));
public DateTime DateOfBirth { get; set; }
}
private static void Main(string[] args)
{
var people = new List<Person>
{
new Person {Name = "Francois", DateOfBirth = new DateTime(1978, 07, 16)},
new Person {Name = "Marichen", DateOfBirth = new DateTime(1982, 07, 28)},
new Person {Name = "Wynand", DateOfBirth = new DateTime(1977, 01, 01)},
new Person {Name = "Theron", DateOfBirth = new DateTime(1972, 06, 15)},
new Person {Name = "Werner", DateOfBirth = new DateTime(1998, 02, 28)},
new Person {Name = "Graeme", DateOfBirth = new DateTime(1935, 09, 03)},
};
var younglings = people
.AsQueryable()
.Where("Age < 30")
.ToList();
foreach (var p in younglings)
Console.WriteLine($"{p.Name} {p.Age}");
Console.WriteLine();
Console.WriteLine("====================================");
Console.WriteLine();
Console.ReadKey(false);
}
} |
This will be supported in the next version by setting a config setting ( The next code will work: class Person
{
public string Name { get; set; }
public object Age { get; set; }
}
var persons = new[]
{
new Person { Name = "Foo", Age = 99 },
new Person { Name = "Bar", Age = 33 }
}.AsQueryable();
var config = new ParsingConfig
{
ConvertObjectToSupportComparison = true
};
var results = persons.Where(config, "Age > 50").ToList(); |
Hi, does it support for 'object' data type?
It always throw an exception:
System.InvalidOperationException: The binary operator Equal is not defined for the types 'System.Object' and 'System.Int32'.
The text was updated successfully, but these errors were encountered: