Quantcast
Channel: EntityFramework Reverse POCO Code First Generator
Viewing all articles
Browse latest Browse all 1642

New Post: add hasoptional relationship which doesn't exist in DB

$
0
0
Please allow me to join with the others in thanking you for the substantial and useful tool.

I have a DB which started with an early EF revision. It successfully transitioned to EF4, then 5. Now we are attempting to position it for the future. I've had an number of issue, but found answers for everything but this so far by trolling the discussion group.

I have two tables, primary table EntryLog, child table ContactedEntryLogDetail. The primary key on both tables is LogEntryId. The child table primary key is not an identity column.

There is no relationship in the db between these two tables. When there is a ContactedEntryLogDetail (which there is not always), the child key entry is supposed to be equal to the parent primary key.

in the old edmx file I see:
</AssociationSet>
      <EntitySet Name="ContactedLogEntryDetails" EntityType="AWCTSDBModel.ContactedLogEntryDetail" />
      <EntitySet Name="LogEntries" EntityType="AWCTSDBModel.LogEntry" />
      <AssociationSet Name="FK_ContactedLogEntryDetailsLogEntry" Association="AWCTSDBModel.FK_ContactedLogEntryDetailsLogEntry">
        <End Role="LogEntry" EntitySet="LogEntries" />
        <End Role="ContactedLogEntryDetail" EntitySet="ContactedLogEntryDetails" />
      </AssociationSet>

      <NavigationProperty Name="LogEntry" Relationship="AWCTSDBModel.FK_ContactedLogEntryDetailsLogEntry" FromRole="ContactedLogEntryDetail" ToRole="LogEntry" />

      <NavigationProperty Name="ContactedLogEntryDetail" Relationship="AWCTSDBModel.FK_ContactedLogEntryDetailsLogEntry" FromRole="LogEntry" ToRole="ContactedLogEntryDetail" />

    <Association Name="FK_ContactedLogEntryDetailsLogEntry">
      <End Type="AWCTSDBModel.LogEntry" Role="LogEntry" Multiplicity="1" />
      <End Type="AWCTSDBModel.ContactedLogEntryDetail" Role="ContactedLogEntryDetail" Multiplicity="0..1" />
      <ReferentialConstraint>
        <Principal Role="LogEntry">
          <PropertyRef Name="LogEntryId" />
        </Principal>
        <Dependent Role="ContactedLogEntryDetail">
          <PropertyRef Name="LogEntryId" />
        </Dependent>
      </ReferentialConstraint>
    </Association>
If I look at the edmx design, I see a 1:0-1 relationship between these tables. I don't see this relationship defined in the db and I can't add this relationship in the db to reverse.

Based on my reading it seems I need an hasOptional statement associated with one of these tables, but I can't figure out where I would put it.

If none of this makes sense, I can code around this problem. But if you see a solution, I would really appreciate it, as this situation occurs with a large number of tables.

Thank you,
jeff landry

Viewing all articles
Browse latest Browse all 1642

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>