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

Inconsistent naming in SingleOrDefault vs FirstOrDefault #67

Closed
fbjerggaard opened this issue Dec 14, 2022 · 6 comments
Closed

Inconsistent naming in SingleOrDefault vs FirstOrDefault #67

fbjerggaard opened this issue Dec 14, 2022 · 6 comments
Assignees
Labels
Milestone

Comments

@fbjerggaard
Copy link

In Linq, SingleOrDefault only returns an entity if exactly 0 or 1 exists whereas FirstOrDefault returns the first (or null) no matter how many exists.

This can be confusing for new users of this package since the repositories use the SingleOrDefault naming, but actually returns a FirstOrDefault behind the scenes.

Are there any reasoning behind chosing one naming scheme over the other and not keeping it consistent?

@garywoodfine
Copy link
Contributor

Sad to say, that may be a mistake on my part to be honest.
I was making changes in real time to help address an issue for another user at the so may have overlooked that
I will try sort that out

@garywoodfine garywoodfine self-assigned this Mar 20, 2023
@KennethScott
Copy link

Any hint as to the direction and timeline on this? I'd like to use this library in a new project, but if it's about to have a breaking change, I may hold off. I'm assuming you'll add methods so you'll have support for both FirstOrDefault and SingleOrDefault. I guess I'm a little leery of how long that might take, given that we'll be writing code and having to remember that it's really not doing what we think it's doing in the meantime, and that it might suddenly change/correct one day if/when we update the package.

Hopefully that makes sense. Nice project though - I like it more than the others I've reviewed.

Thanks-

garywoodfine added a commit that referenced this issue Mar 23, 2023
Fixed issue relating to #67

Updated the repository methods to return SingleOrDefault methods as are advertised by the method signatures!
@garywoodfine
Copy link
Contributor

Implementing the fix now. This will obviously be a breaking change version update.
I incremented the version to 4.0.0 should be ready to install by the time you read this.

Thanks for pointing this out! Clearly I missed that.

@KennethScott
Copy link

Hey not to pile on, but if you're making changes, what do you think about adding support for AsSplitQuery?

I was thinking it might just be another optional boolean on the method like, and then conditionally tacking it on to the query:

public async Task<T> SingleOrDefaultAsync(....bool asSplitQuery = false) {
    ...
    if (asSplitQuery) query = query.AsSplitQuery();
    ...
}

But I have not had a chance to actually test it. Could always do it later as a non-breaking change too. Just thought I'd mention it.

Thanks again-

@garywoodfine
Copy link
Contributor

garywoodfine commented Mar 24, 2023

If I'm perfectly honest, I don't even know what a split query is. I've not come across that specific functionality so I'd have to get my head round it first and understand it.

Feel free to submit a Pull Request with your initial thoughts or ideas and I can evaluate whether if it works.

I was considering implementing the Specification Pattern for the methods to enable creating Query specifications which would make the process of defining queries a lot better, instead of having so many argument overloads on the methods.

@garywoodfine
Copy link
Contributor

BTW I moved the Split Query request to a new issue as I will go ahead and close this one.

Thanks all for the feedback its really appreciated helps me to focus on the library knowing that people are actually using it out there!

@garywoodfine garywoodfine added this to the 4.0.0 milestone Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants