English 中文(简体)
AssociationSet in EF4
原标题:AssociationSet in EF4
  • 时间:2011-01-26 07:35:00
  •  标签:
  • .net
  • c#-4.0

我是EF4的开端人,我无法理解 file子档案中的内容。

任何人都可以向我解释协会的好处。 我认为,协会要素代表了各表之间的关系,因此,我应该使用协会。

感谢

最佳回答

协会是一个协会的集装箱。

当我们有合同和地址类型时,让我们从简单的个案开始。 其关系可描述为:

<Association Name="FK_Address_Contact">
  <End Role="Contact" Type="SampleModel.Contact" Multiplicity="1">
    <OnDelete Action="Cascade" />
  </End>
  <End Role="Address" Type="SampleModel.Address" Multiplicity="*" />
  <ReferentialConstraint>
    <Principal Role="Contact">
      <PropertyRef Name="ContactID" />
    </Principal>
    <Dependent Role="Address">
      <PropertyRef Name="ContactID" />
    </Dependent>
  </ReferentialConstraint>
</Association>

你可以在这里看到,接触者可以有许多地址。 我们在此指出,这两种说法之间都有提及。 但是,如果在合同类型中,我们实际上能够有两个或两个以上地址,那么我们如何能够描述一个案例。 例如,工作压力和家庭压力。 在协会内,我们只能描述两种类型相互参照的事实,但在协会内部,我们还可以描述一种类型可以使用两种对其他类型同等的提法。

对于这种情况,我们可以界定下一个xml:

<EntityContainer Name="ContactsContainer" >
  <EntitySet Name="WorkContacts" EntityType="SampleModel.Contact" />
  <EntitySet Name="HomeContacts" EntityType="SampleModel.Contact" />
  <EntitySet Name="WorkAddresses" EntityType="SampleModel.Address" />
  <EntitySet Name="HomeAddresses" EntityType="SampleModel.Address" />
  <AssociationSet Name="ToWorkAddress" Association="SampleModel.FK_Address_Contact">
    <End Role="Contact" EntitySet="WorkContacts" />
    <End Role="Address" EntitySet="WorkAddresses" />
  </AssociationSet>
  <AssociationSet Name="ToHomeAddress" Association="SampleModel.FK_Address_Contact">
    <End Role="Contact" EntitySet="HomeContacts" />
    <End Role="Address" EntitySet="HomeAddresses" />
  </AssociationSet>
</EntityContainer>
问题回答

暂无回答




相关问题
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 ...

热门标签