-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Removed generic type constraint in extension methods #62
base: master
Are you sure you want to change the base?
Conversation
- Allows TEntity to be a value type.
hello @tiwahu sorry for the late answer. Thanks for your contribution. |
@romantitov, sorry for such a late reply! This library is pretty awesome and simplified tests where we were starting to do it ourselves. At some point we encountered a scenario where the I did something manual to work around going through the extension method, which has the complier restriction. The |
@tiwahu sorry for the late answer. Thank you for your feedback. I’m really glad to hear that you find I carefully reviewed your comments, but the specific use case you described is still a bit unclear to me. The The scenario you mentioned, where a database query returns specific fields of entities, is already supported by the current implementation. For an example, you can take a look at the Since an entity represents records in a database, I’m having difficulty imagining a scenario where an entity could be of type |
@romantitov a little sooner this time. 😉 Looking at my old notes (i.e., comments in code), I was able to work around the extension method constraint by instantiating a
Of course, most of the time in apps using this library, the Here's the cool part... Imagine database queries that only need values out of a single column of a table after applying some joins, where clauses, and sorting. For example, code doing a search for a paginated batch of ids, mapping to records, that some "other" code uses for some other purpose. The LINQ selects for those queries return an Test cases for that "other" code wanted to mock the results that it would get from async methods that returned var ids = new TestAsyncEnumerableEfCore<long>(new[] { 4L, 8L, 15L, 16L, 23L, 42L }); That it isn't nearly as elegant or obvious as your excellent extension methods, though. It seems like the extension methods constraints are arbitrary since the code works without it. I'm proposing the idea of removing the constraint. I can't think of a reason for it to be there, since any It's been a while since I looked at this. Hope that makes sense. Of course, I should figure out where to put the test cases in here for value types specifically! Though, the fact that the projects compile (or did back when I did it) without the class constraint is a pretty good test case. |
PR Details
Description
TEntity
to be a value type.The extension methods had a generic type constraint that prevented
IQueryable<T>
whereT
is a value type from being mocked.Related Issue
How Has This Been Tested
long
forTEntity
.Checklist
I have added tests to cover my changes.