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

UpdateGraph fails if PrimaryKey is nullable in Entity POCO, but not null in database #22

Closed
davisnw opened this issue Dec 21, 2013 · 2 comments · Fixed by #40
Closed
Assignees
Milestone

Comments

@davisnw
Copy link

davisnw commented Dec 21, 2013

If you have an entity class like so:

public class Foo { Guid? Id { get; set; } }

and your database table is

create table dbo.Foo ( Id uniqueidentifier NOT NULL )

Then UpdateGraph fails with an exception that "there is no binary == operator between Guid? and Guid".

@davisnw
Copy link
Author

davisnw commented Dec 21, 2013

(I should perhaps mention that the above scenario is motivated by the desire to clearly know the difference between a new entity and a persisted entity within the POCO object model. With a nullable id, it will default to null when an object is "newed up" clearly communicating that this is a non-persisted entity. However, an entity retrieved from entity framework will always have a non-null id).

@refactorthis
Copy link
Collaborator

I had a quick look at this, the expression is created at DbContextExtensions.cs:282. The comparison is written in an Expression and I can't assume a type for the Id. So it's going to be hard to know what to convert it to to ensure equality. Perhaps I can check to see if one is a Nullable and convert the other so that they are even. I'll look into this soon.

@ghost ghost assigned refactorthis Jan 3, 2014
@ghost ghost mentioned this issue Feb 1, 2014
@ghost ghost closed this as completed in #40 Feb 6, 2014
ghost pushed a commit that referenced this issue Feb 6, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants