-
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
Find by primary key using named/typed parameters #30587
Comments
@dvoreckyaa Do you have a general purpose API proposal here? The examples above all seem specific to certain entity type with known key configurations. |
@ajcvickers , not it is not specific to certain entity type. The mentioned generator takes a DbContext (should be inherited fom DbContext) then
public void GenerateFileFromType<T>(string outputFolder) where T : DbContext The PK is obtained from the model definition: protected override void OnModelCreating(ModelBuilder modelBuilder)
{
...
#region Localization
modelBuilder.Entity<Localization>()
.HasKey(b => new { b.ApplicationID, b.Culture, b.Key });
#endregion
...
} |
@dvoreckyaa if I understand your proposal correctly, this would be a source generator provided by EF Core, which generates Find extension methods over concrete A source generator like this would need to access the user's EF model, in order to know about entities and their primary key properties. There are unfortunately various problems that make it unfeasible for a source generator to know about the model, see #25009 (comment) for more details. In any case, we've rarely seen any actual user complaints about bugs because of this, and it's fairly trivial for users to add their own extensions manually, if they so wish. There's also the option to just use a LINQ query to load an entity type from the database (i.e. To summarize, in an ideal world something like this would indeed exist; but the significant issues in actually doing this, coupled with the relative low value and alternative methods for achieving almost the same, make this pretty low value in my opinion. |
@roji, it sounds reasonable, thanks for the clarification. |
Hi all,
we have possibility to find an entity usig Find methdod
where we have to pass all paramters as object array. For me it seems a bit inconvenient and can lead to mistakes.
I would suggest improving this by adding FindByPrimaryKey methods that will accept named and typed parameters.
Maybe this functionality is already implemented but I could not find.
Actually, a few years ago I implemented a generator that creates an extension for a DbSet to support FindByPK with typed parameters.
https://github.com/dvoreckyaa/FindByPKGenerator
The text was updated successfully, but these errors were encountered: