Skip to content
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

SqlFunctions -> System.NotSupportedException #106

Open
pfaustinopt opened this issue Apr 4, 2018 · 9 comments
Open

SqlFunctions -> System.NotSupportedException #106

pfaustinopt opened this issue Apr 4, 2018 · 9 comments
Assignees

Comments

@pfaustinopt
Copy link

pfaustinopt commented Apr 4, 2018

Hello!

I'm facing a problem with Effort and methods from the SqlFunctions class. In my query repository I've the following expression on a Where clause:

Where( x => x.Weekday == SqlFunctions.DatePart("weekday",date))

When running my unit tests with effort, i get the following message:
System.NotSupportedException: The specified method 'System.Nullable1[System.Int32] DatePart(System.String, System.Nullable1[System.DateTime])' on the type 'System.Data.Entity.SqlServer.SqlFunctions' cannot be translated into a LINQ to Entities store expression.

Effort does not support the usage of methods from the SqlFunctions class?

@pfaustinopt pfaustinopt changed the title SQLFunctions -> System.NotSupportedException SqlFunctions -> System.NotSupportedException Apr 4, 2018
@JonathanMagnan
Copy link
Member

Hello @pfaustinopt ,

Do you think you could provide us a test project with this issue?

It will make easier/faster for my developer to getting started for investigating it.

We now always ask for a project since we found out that most issues are missing some essential information or are resolved by the requestor when creating it

(Even if the issue seem very easy to reproduce, by getting a test project, it allow us to give a faster support and better experience for the support of all our free libraries)

Best Regards,

Jonathan

@JonathanMagnan JonathanMagnan self-assigned this Apr 4, 2018
@pfaustinopt
Copy link
Author

All you have to do is run the test method I provide.
Let me know if you have any problems running this example.

UnitTestProject1.zip

@JonathanMagnan
Copy link
Member

Thank you for the project @pfaustinopt ,

We can successfully reproduce it.

We started to investigate how it's working with EntityFunctions:

var find = context.MyEntities.Where(x => monday < EntityFunctions.AddDays(monday, 1)).FirstOrDefault();

and we will try to replicate the code with SqlFunctions and check if that could be supported using a similar code.

Best Regards,

Jonathan

@JonathanMagnan
Copy link
Member

Hello @pfaustinopt ,

After looking at it, we faced some more issue with your UnitTest.

Such as the DayOfWeek.Monday in c# doesn't have the same value as the weekday in SQL.

So even if we make it work, that will in fact doesn't work since the C# value you will save (int)DayOfWeek.Monday will not be equal to the value when a SQL will be used.

Let me know if that's clear or you need a better explanation.

Best Regards,

Jonathan

@pfaustinopt
Copy link
Author

I was aware of that, that's why on my code I end up using (int)DayOfWeek.Monday + 1.

@JonathanMagnan
Copy link
Member

Great,

We will continue to investigate it more this week. Is seem harder than we first thought.

Best Regards,

Jonathan

@yvdorofeev
Copy link

Just curious if there was any update on this.

@laleksiunas
Copy link

laleksiunas commented Aug 20, 2019

If anybody still stumbles upon this issue, you can try to use Day property from the System.DateTime which seems to be translated to Sql in exactly the same way.

@pilarodriguez
Copy link

Any update on this? We found the same issue using SqlFunctions.DateAdd("day", 30, date)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants