zzzprojects / Eval-Expression.NET

C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
https://eval-expression.net/
Other
449 stars 86 forks source link

Exception when calling ToString on enum property? #84

Closed Josrph closed 3 years ago

Josrph commented 4 years ago
public enum CustomerType { TypeA, TypeB, TypeC, }
public class Customer
{
        public int ID { get; set; }
        public string Name { get; set; }

        public string Address { get; set; } = "/";
        public string PhoneNum { get; set; } = "/";
        public CustomerType CustomerType { get; set; }
 }

var ctx = new AppDbContext();

var list1 = ctx.Customers.SelectDynamic(x => "new { val = x.ID.ToString() }").ToList(); // Works fine

var list2 = ctx.Customers.SelectDynamic(x => "new { val = x.CustomerType.ToString() }").ToList(); // NotSupportedException

System.NotSupportedException: 'LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.'

JonathanMagnan commented 4 years ago

Hello @Josrph ,

Does it work without our library?

var list2 = ctx.Customers.Select(x => new { val = x.CustomerType.ToString() }).ToList();

It looks more lime a limitation with the ORM than our library.

Otherwise, can you provide us a runnable project with the issue so we could investigate it? Or please provide us all the required information do reproduce it such as the ORM used and version.

We tried with EF Core 3.x and it worked fine with our library.

Best Regards,

Jon

Josrph commented 4 years ago
var list1 = ctx.Customers.Select(x => new { val = x.CustomerType.ToString() }).ToList(); // works fine which proves it's not a limitation with the ORM
var list2 = ctx.Customers.SelectDynamic(x => "new { val = x.CustomerType.ToString() }").ToList();// NotSupportedException

PS: am using .Net 4.7.2 with EF 6.4.4 Z.EntityFramework.Extensions 4.0.91 Z.EntityFramework.Plus.EF6 1.12.32 Z.Expressions.Eval 4.0.15

JonathanMagnan commented 4 years ago

Thank you @Josrph ,

We successfully reproduced the issue.

We will look at it.

JonathanMagnan commented 4 years ago

Hello @Josrph ,

The v4.0.19 has been released.

Could you confirm that the issue has been successfully fixed?

Josrph commented 3 years ago

Perfect... as of v4.0.19 the issue has been successfully fixed!

JonathanMagnan commented 3 years ago

Great Josrph!

Don't hesitate to contact us for further assistance.

Best regards,

Jon