dj-nitehawk / MongoDB.Entities

A data access library for MongoDB with an elegant api, LINQ support and built-in entity relationship management
https://mongodb-entities.com
MIT License
547 stars 70 forks source link

allow all IDs to not be nullable #211

Closed dberry-rcs closed 1 year ago

dberry-rcs commented 1 year ago

Here is a PR for the proposed IsSetId.

dj-nitehawk commented 1 year ago

renamed the method to HasDefaultID and inverterted the check.

seems like the right way to go.

fyi, this is what the id generator interface in the driver also does.

so basically we've just integrated the driver's optional behavior as a requirement in our library.

dj-nitehawk commented 1 year ago

so... all that's left now is to sort out that failing test right? it fails for you locally right? for the life of me i can't get it to fail on my machine so i can see what the hell is going on :-(

dberry-rcs commented 1 year ago

We also have the issue that for relationships to work, the serialization code needs to be added to the AsBsonIdAttribute for each id type someone wants to use. Do you have any ideas on how to make the relationships work without [AsBsonId]?

dj-nitehawk commented 1 year ago

so i've been looking in to the relationships thing with custom ID types. can't come up with anything viable unfortunately :-( maybe it would have to be documented as a known limitation. custom ID types will not work with built-in relationships or relationships are only supported with the following ID types: ObjectId, string, Int64/long

dberry-rcs commented 1 year ago

I say push it with the appropriate warnings. Would it make sense to have relationships as a separate nuget package?

dj-nitehawk commented 1 year ago

yeah let me merge it to master and do a beta build so we can test it out a bit more.

Would it make sense to have relationships as a separate nuget package?

not sure what that would achieve though. what made you think that? because we're not taking away the existing relationship functionality for ppl who have string IDs.

dberry-rcs commented 1 year ago

I don't use relationships, so it is just baggage to me. Also, if we do a rewrite of relationships we could have the old and new as separate libraries and people can choose what they prefer.

dj-nitehawk commented 1 year ago

pushed v22.1.0.1-beta to nuget if you wanna try it.

this failing test needs to be figured out before we move forward i guess. damn thing only fails for me in CI/CD and won't locally so i can debug :-(

dberry-rcs commented 1 year ago

pushed v22.1.0.1-beta to nuget if you wanna try it.

this failing test needs to be figured out before we move forward i guess. damn thing only fails for me in CI/CD and won't locally so i can debug :-(

What IDE are you using? I get the error with Rider on Windows 10.

dj-nitehawk commented 1 year ago

visual studio 2022 enterprise does rider have a free version at all?

dberry-rcs commented 1 year ago

free 30-day trial

dj-nitehawk commented 1 year ago

v22.1.0.2-beta pushed to nuget. let's test it out for a month or two.

dberry-rcs commented 1 year ago

I just put this in our dev env. I will go to prod if no issues found. The upgrading of the nuget package worked with no compile errors. One test failed due to it taking slightly longer now. 0.2s wait, which I made one full second.

dj-nitehawk commented 1 year ago

been trying to upgrade one of my larger projects and it had several hundred compile errors because One<T>.ID became an object where it used to be string. so it required me to update each of the lines with casting to string from object.

so i pushed a new beta v22.1.0.4-beta which takes care of that. but now custom id types will require the use of One<TEntity,TIdentity> generic overload. like this: https://github.com/dj-nitehawk/MongoDB.Entities/blob/4948fbd73658607a66829811589876c9bd7e7d01/Tests/Models/Author/AuthorInt64.cs#L19

other than that, the only breaking change needed was to update Many<T> to Many<TChild,TParent> which wasn't used that much in my projects.

dberry-rcs commented 1 year ago

How did you make out? Will you be pushing a release?

dj-nitehawk commented 1 year ago

current build seems to be working good in my projects. will push out the final version soon. need to find the time to write/update the docs first.