How to create EntitySet for all DBSet<> in DbContext dynamically?
Open
@xuzhg is already working on this.
Since May 21, 2021.
investigated
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
var odataBuilder = new ODataConventionModelBuilder();
When using the AddEntitySet(), my endpoints fail with the error:
System.InvalidOperationException: 'The entity set 'foo' is based on type 'foo' that has no keys defined.'
var t = typeof(foo);
odataBuilder.AddEntitySet(t.Name, odataBuilder.AddEntityType(t));
I am using Ef Core with fluent api to set key and navigation attributes
[Table(nameof(foo))]
public partial class foo:
IEntityTypeConfiguration<foo>
{
void IEntityTypeConfiguration<foo>.Configure(EntityTypeBuilder<foo> builder)
{
_ = builder.HasKey(x => x.RecKey);
_ = builder.HasIndex(x => x.Name).IsUnique();
}
}
How can I dynamically configure each EntitySet for my DbContext? Explicitly defining each of the hundreds of DbSet<> in my DbContext is both time consuming and error prone.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.