Fluent API: defining one to many
Models classes :
Mappings:
So I've commented out one, each time and ran the database, keeping one at the time,
builder.HasMany<ShippingAddress>(c => c.ShippingAddressNavigation).WithOne(s => s.CustomerNavigation).HasForeignKey(s => s.CustomerId);
builder.HasOne<Customer>(S => S.CustomerNavigation).WithMany(c => c.ShippingAddressNavigation).HasForeignKey(a=>a.CustomerId);
appears i get the same results
so here are my questions:
1. is there any difference between defining the relationship from Customer or ShippingAddress that I've failed to observe? Am I right to assume I'm achieving the same thing just from different side of the relationship?
2. is one way better in terms of anything (convention, readability, etc)?7 Replies
1. No difference at all, no
2. Matter of preference, I'd say
Thanks a lot! appreciate it!
As a side note, you can take advantage of the "fluent" part of "fluent API" and not repeat
builder.
so many times
(: appreciate the tip!
gotta add builder again after hasKey though right?
Maybe?
You can just reorder the calls so it's the last one
Generally, the fluent pattern is based around the idea of a method returning the thing it's being called on, so some sort of
So check if the method returns the builder
If so, you can continue chaining off of it
got it!
so has key does't wanna play nice with others but all the other ones are fine 😛
thank you so much again!
:Ok: