-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
DbSet<T>.Find by alternate key or predicate #12469
Comments
@BalassaMarton This has been discussed several times in the past--for example, see #10303. Find has two advantages over executing a query:
Any time we look at expanding the Find API we always come to the conclusion that it would be better to just write a query. That is, it doesn't retain the first advantage of Find. As for the second advantage, #1948 covers how this could be added to normal LINQ queries. Taking these two things together, the conclusion has been that we should implement #1948 instead. |
@ajcvickers This is something that I've come across in an actual ETL project. Take this very simple example where we have a flat input with foreach (var sproj in source) {
var proj = db.Projects.FirstOrDefault(p => p.Code == sproj.ProjectCode) ?? new Project { Code = sproj.ProjectCode };
proj.Status = sproj.ProjectStatus;
db.Projects.Update(proj);
} When we hit the same project code a second time, |
@BalassaMarton We discussed this in triage and came to the conclusion that once #7391 (as referenced from #10303) is implemented, then it will be possible to easily to efficient lookup by key or alternate key in the state manager, which will allow different types of Find to be implemented as extension methods. |
Sounds great, thank you. |
|
It does? That would be a huge issue in a multi-tenant environment. |
Sorry I was wrong, I thought they were only used for queries. |
It would be nice to have a version of
DbSet<T>.Find
that works with an alternate key or predicate.The proposed signatures:
Functionally, this can be achieved with extension methods, by first searching the local set, but it would perform better if there was an identity map for alt. keys and
Find
would search using that.The text was updated successfully, but these errors were encountered: