Using the same configuration for both ODataModelBuilder and Entity Framework Core

24 Views Asked by At

I get this error

System.InvalidOperationException: The entity set 'EmployeeDto' is based on type '[namespace].EmployeeDto' that has no keys defined.

I know that I can solve this just by putting the [Key] attribute on the ID property for that class, but I have several classes to edit, since we are migrating a huge enterprise project from .NET Framework 4.7 to .NET 6.

The thing is this: I already have defined the key for all the entities in this way:

public class EmployeeMapDto : IEntityTypeConfiguration<EmployeeDto>
{
    public EmployeeMapDto()
    {
    }

    public void Configure(EntityTypeBuilder<EmployeeDto> builder)
    {
        builder.HasKey(x => new { x.ID });
        builder.ToTable("Employee", "dbo");
    }
}

And I'd like to use the same configuration for both Entity Framework and ODataBuilder. Is it possible?

0

There are 0 best solutions below