Hi, I searched around the repo, but I didn't found nothing related, so if this is a dupe, feel free to close.
What I would like to have is the ability to define FK without navigation property, even better I would like to create a shadow state FK, to keep my class clean.
I would like to have this feature to implement e.g. a very simple auditing mechanism on each entity, to keep track of the last user that has updated a certain entity, but i would like to keep these fields off my entity.
Now I'm not able to create a FK without a navigation property, so IMHO this could be a quite useful feature.
Regards, Max
It's ugly, but possible:
C#
modelBuilder.Entity<Post>(
x =>
{
x.Property<int>("BlogId");
x.References<Blog>().InverseCollection().ForeignKey("BlogId");
});
Thank you @bricelam, it's quite hard to figure it out :) but this is what I need!
Discussed and decided that while the API isn't super awesome for this scenario, it is probably less common and we are ok with sticking with what we have for the moment. We could always add some sugar APIs later if we wanted to.
Is this still valid as for the version 1.1.1 ?,
I can't find the method Reference of EntityTypeBuilder<T>
RTM syntax:
C#
modelBuilder.Entity<Post>(
x =>
{
x.Property<int>("BlogId");
x.HasOne<Blog>().WithMany().HasForeignKey("BlogId");
});
@bricelam wonderful :)
could i ask what is benefit of removing Navigation Property from Entity class? Can we use eager loading form then?
Most helpful comment
RTM syntax:
C# modelBuilder.Entity<Post>( x => { x.Property<int>("BlogId"); x.HasOne<Blog>().WithMany().HasForeignKey("BlogId"); });