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

Exception when compare default value with StronglyTypedIdBackingType.String #32

Closed
nhuthan opened this issue Mar 22, 2021 · 5 comments
Closed

Comments

@nhuthan
Copy link

nhuthan commented Mar 22, 2021

Example code

[StronglyTypedId(backingType: StronglyTypedIdBackingType.String)]
public partial struct UserId{ }

public class User{
    public UserId Id {get; set;}
}

...
var user = new User();
if(user.Id == UserId.Empty) --> throw exception (using Value.CompareTo when Value is null)
@andrewlock
Copy link
Owner

Yeah, that's an inherent problem with using a reference type in the struct. The question is, how would you expect this to behave? We could throw if you try to create a UserId with a null string. We could use ?. in the CompareTo. What are your thoughts?

@nhuthan
Copy link
Author

nhuthan commented Mar 25, 2021

@andrewlock I think use ?. is good idea. It will working well for EF.

@nhuthan
Copy link
Author

nhuthan commented Mar 26, 2021

I created a pull request here #33

@andrewlock
Copy link
Owner

I've released a beta version of a major update to the library converts to using Source generators. There's quite a few breaking changes in the release, so please make sure to check the release notes for how to update, but I'd appreciate any feedback you have before I do a final release! It fixes this issue too.

I've also written a blog post announcing the update that goes into a bit more details: https://andrewlock.net/rebuilding-stongly-typed-id-as-a-source-generator-1-0-0-beta-release

Thanks! 🙂

@andrewlock
Copy link
Owner

I believe this issue is solved in the 1.0.0 beta release, so closing this for now. Feel free to re-open if it doesn't work for you

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

No branches or pull requests

2 participants