English 中文(简体)
实体框架4:继承(表型)——比较表有一个综合PK
原标题:Entity Framework 4: Inheritance (table per type) - Derived table has a composite PK

如果衍生表格具有一个综合的主要关键点,实体框架4中是否有“按类型分列的”继承?

下面是我的表格:

TABLE: ConfigurationKey (Base Entity)
PK: Id

TABLE: ConfigurationKey_Device (Derived Entity)
PK: ConfigurationKeyId (FK to ConfigurationKey.Id)
PK: DeviceId (FK to Device.Id)

就其价值而言,碎块是抽象的,其他类型则来自混凝土。

我使用EF设计师:

  • Added the inheritance rule
  • Deleted ConfigurationKeyId from ConfigurationKey_Device
  • Deleted the FK linking ConfigurationKey_Device to ConfigurationKey
  • Updated the mapping of the ConfigurationKey_Device.ConfigurationKeyId column to the inherited Id property.

我现在发现的错误是:

Error 3003: Problem in mapping fragments starting at line xxx:All the key properties (ConfigurationKeys.Id) of the EntitySet ConfigurationKeys must be mapped to all the key properties (ConfigurationKey_Device.ConfigurationKeyId, ConfigurationKey_Device.DeviceId) of table ConfigurationKey_Device.

Thanks, Chris

最佳回答

The error message answers to your question itself.
You are actually trying to inherit from an entity with one-column key with an entity with two-column key.
It seems the better solution will be either to have a ComplexType enclosing the common set of properties, or a common interface implementing the necessary functionality.

问题回答

暂无回答




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签