Entity Framework foreign key that is not a primary key

c# entity-framework entity-framework-6 guid sql

Accepted Answer

I wanted to switch from only IDs to GUIDs for uniqueness and changed the tables.

To assure uniqueness, you don't really need to convert to GUIDs. As long as they are configured as your main keys, your IDs (regardless of what type they are, like integers), will be assured to be distinct.

I have read that GUIDs as primary keys are not recommended for performance reasons. So I kept the IDs

tenantGuid uniqueidentifier foreign key to tenants.tenantGuid

Keeping IDs as the main key won't matter since queries will still be run on the GUID, assuming you're talking about the speed of "joins" while using GUID as the key.

Now entity framework is going wild just dismissing all relationships because the guids are not part of the primary key.

How am I support to solve this?

You would be better served, in my opinion, not figuring this out and instead opting to return to your former database architecture, which makes use of the integer ID. Alternatively, you might use GUID as your main key (removing integer ID in the process).

1
11/22/2017 7:15:26 PM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow