FK on Guid
I have the following two classes
Where each database record will have it's own unique ID, but the relationship between the two records is based on name (due to pulling the data from a 3rd party system). However, this throws an error when attempting to migrate for
'PiCollectiveIdentityMapping.Mappings' with foreign key properties {'IdentityName' : string} cannot target the primary key {'Id' : Guid} because it is not compatible
What is the proper way to build the relationship?5 Replies
You set the FK on the "one" side of "one to many"
And, I believe, you will need to configure the name to be a key
I moved it from attribute based to the onModelCreating. I like to keep them in the models but sometimes they're just dumb
another option is to use IEntityTypeConfiguration classes, then you can keep entity configuration out of the dbcontext and still use the fluent API
Creating and Configuring a Model - EF Core
Overview of creating and configuring a Entity Framework Core model via Fluent API, Data Annotations and conventions.
Oh right, I forgot about that method. That's certainly an option and if I end up with more scenarios where the attribute route doesn't cover the needs, I'll look to bring that back in