We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi,
There is an error in AddOrUpdate method. Let's look on such example:
public class Test { public Guid? SomeKey { get; set;} } protected override void Seed(TestContext context) { var entity = new Test() { SomeKey = Guid.NewGuid()}; context.Tests.AddOrUpdate(t => t.SomeKey, entity); }
Running such code creates error:
The binary operator Equal is not defined for the types 'System.Nullable`1[System.Guid]' and 'System.Guid'.
Problem lays in invalid condition createion based on identifier parameter in AddOrUpdate method:
Expression.Equal( Expression.Property(parameter, pi.Single()), Expression.Constant(pi.Last().GetValue(entity, null)))
Expression.Property returns expression of type Guid?. Expression.Constant return expression of type Guid. And Equals cannot join it.
The solution is to add parameter to Expression.Constant about type of property.
Expression.Constant(pi.Last().GetValue(entity, null), pi.Last().PropertyType))
Then it will cast this expression to be Guid? and it will run property.
I think that this will also occure on EF7. but i didn't use it already.
The text was updated successfully, but these errors were encountered:
Ported from CodePlex https://entityframework.codeplex.com/workitem/2907
Sorry, something went wrong.
Great that you are working on this, hopefully it should also solve https://entityframework.codeplex.com/workitem/2486 which might be a duplicate of the other codeplex item
Yeah, just adding the property's type to the constant expression should do it (see my corresponding Stack Overflow answer).
I could find some time for this next week or the week after. Please let me know, if I should look into it and prepare a PR if successfully.
Is there a work around for this? I tried copy this code into my project, but it uses internal types. Edit: I used a combo of http://stackoverflow.com/questions/15405875/ef5-migrations-seed-addorupdate-with-a-nullable-selection-criteria/29339351#29339351 modified with http://stackoverflow.com/questions/17710769/can-you-get-the-dbcontext-from-a-dbset/17712575#17712575 to make it a drop-in replacement
Successfully merging a pull request may close this issue.
Hi,
There is an error in AddOrUpdate method. Let's look on such example:
Running such code creates error:
Problem lays in invalid condition createion based on identifier parameter in AddOrUpdate method:
Expression.Property returns expression of type Guid?. Expression.Constant return expression of type Guid. And Equals cannot join it.
The solution is to add parameter to Expression.Constant about type of property.
Then it will cast this expression to be Guid? and it will run property.
I think that this will also occure on EF7. but i didn't use it already.
The text was updated successfully, but these errors were encountered: