I can't find any information about the support of EF Core 7 for XOR relationship constraint.
Is the following relationship supported?
Related
I've started working on a mature code-first EF6 project. There is no EDMX file. I can't find anywhere in the code where the names of the joining tables that support many-to-many relationships is specified, and yet EF knows what they are. How?
The EF model is built by a set of conventions, which you can override with attributes or code-based configuration.
I am using EF core 2.0 and using scaffolding reverse engineering database first to generate models.
some of tables does not have any primary key and EF Unable to generate entity type for table.
Any advice how can I do this other then adding manually.
So far either Entity Framework or Entity Framework Core does not support generating table from EF/EF Core model class without primary key.
But this is a requested feature in Entity Framework Core. Here is the details about it:
Allow code generation for tables without a primary key
You could upgrade to EF core 3.0 which is currently in preview, that is now possible.
2019 Update / TLDR; switch to Entity Framework Core (or whatever else)
While missing some "Features", EF Core properly honors Alternate Keys (aka Unique Constraints) in addition to Primary Keys and thus does a much better job of honoring Relational Algebra. YMMV otherwise; at least it supports many more SQL schemes correctly.
This support added was in the (very outdated) EF Core 1.0 release.. a bit disappointing that the original EF never had this design(ed!) flaw addressed.
This may be related to my other question - which seems to be that either:
Entity Framework is a terrible Relational Algebra mapper1 or;
(which I am hoping for) I am overlooking something with SSDL/CSDL and the EDMX model or EF mappings in general.
I have a Schema First model and the schema looks like this:
ExternalMaps
---
emap_id - PK
Melds
---
meld_id - PK
emap_id - >>UNIQUE INDEX<< over not-null column, FK to ExternalMaps.emap_id
For verification, these are scripted as the following, which should result in a multiplicity of ExternalMaps:1 <-> 0..1:Melds2.
ALTER TABLE [dbo].[Melds] WITH CHECK ADD CONSTRAINT [FK_Melds_ExternalMaps]
FOREIGN KEY([emap_id]) REFERENCES [dbo].[ExternalMaps] ([emap_id])
CREATE UNIQUE NONCLUSTERED INDEX [IX_Melds] ON [dbo].[Melds] ([emap_id] ASC)
However, when I use the EDMX designer to update from the database (SQL Server 2012), from scratch, it incorrectly creates the Association / Foreign Key relation as ExternalMap:1 <-> M:Meld.
When I try to change the multiplicity manually for the Meld (via the "Association Set" properties in the designer) side to either 1 or 0..1, I get:
Running transformation: Multiplicity is not valid in Role 'Meld' in relationship 'FK_Melds_ExternalMaps'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *.
(As with my other question, this seems to be related to Unique Constraints not being correctly registered/honored as Candidate Keys.)
How can I get EF to honor the 1 <-> 0..1/1 multiplicity, as established by the model?
1 While I hope this is not the case, I am having no end to grief when trying to get EF to map onto a perfectly valid RA model: LINQ to SQL (L2S) does not have this problem. Since my other question was not trivially answered for such a popular ORM, I am losing faith in this tooling.
2 It is by design that the FK is not the other way: "Though shalt not have nullable foreign keys." - It is also not the case that it's a "shared" PK as this answer from 2009 suggests as a fix.
I am using EF 6.1.1, VS 2013 Ultimate, and am not going to use any "OO subtype features" - if that changes anything.
EDIT sigh:
Multiplicity is not valid because the Dependent Role properties are not the key properties? (from 2011) - is this still the case for the EF "Microsoft-endorsed Enterprise-ready" ORM in 2014 2015?
At this rate the next time someone asks why EF wasn't used I'll have a large set of reasons other than "LINQ to SQL works just fine" ..
The problem is that Entity Framework (from EF4 through EF6.1, and who knows how much longer) does not "understand" the notion of Unique Constraints and all that they imply: EF maps Code First, not Relational Algebra *sigh*
This answer for my related question provides a link to a request to add the missing functionality and sums it up:
.. The Entity Framework currently only supports basing referential constraints on primary keys and does not have a notion of a unique constraint.
This can be expanded to pretty much all realms dealing with Unique Constraints and Candidate Keys, including the multiplicity issue brought up in this question.
I would be happy if this severe limitation of EF was discussed openly and made "well known", especially when EF is touted to support Schema First and/or replace L2S. From my viewpoint, EF is centered around mapping (and supporting) only Code First as a first-class citizen. Maybe in another 4 years ..
I'm using VS 2013 Premium with EF 6 and want to use Model First with Table per Hierarchy. I've been searching for 2+ hours for a solution to no avail.
In the Model Designer, I only have TPT as a choice. It seems that TPH is in the "Entity Designer Database Generation Power Pack" for VS 2010 but I read that this doesn't work in 2012 so I assume it doesn't for 2013 as well. I saw that for Code First TPH is the default inheritance strategy so is the answer to convert a Code First project using TPH to Model First? Can Model First and TPH even be done? What are my options?
I would always do it model first.
Here is a (simple) manual way to make TPH after you generate entities from database:
http://msdn.microsoft.com/en-us/data/jj618292
We have a table which has a composite primary key consisting of two foreign keys. I know that this should work on EF 4.0 but we get an update exception when trying to insert the referenced entities when using EF 3.5.
I tried to look for confirmation whether or not EF 3.5 supports this but the answer seems to always be "Yes, EF 4.0 supports this".
So I'm asking here:
Does entity framework 3.5 support composite keys made up from foreign keys?