Closed wadebee closed 6 years ago
Ok, I figured this out looking at the source code. Looks like the IQueryable.OData extension method allows you to pass in an IEdmModel. I declared my types (with custom keys) and passed it in. Query filtered as expected.
Thanks, Wade
Hi Wade,
Also you can use System.ComponentModel.DataAnnotations.KeyAttribute
to define an entity key.
using System.ComponentModel.DataAnnotations;
public class SampleWithCustomKey
{
[Key]
public string MyDomainKey { get; set; }
public DateTime DateTime { get; set; }
}
Thanks, Ihar
[Key] attribute works. But when scaffolding (db first) the entity model is recreated automatically which reverts the manual changes.
Is it possible to specify the key during OnModelCreatingPartial?
partial void OnModelCreatingPartial(ModelBuilder modelBuilder) {
modelBuilder.Entity<SampleWithCustomKey>().HasKey(x => x.MyDomainKey);
}
By convention the entity key property is Id. How do I modify my EntityType EDM registration to reflect my domain key (eg: builder.EntityType.HasKey(t => t.MyDomainKey)?