c# - Can you customise foreign key names in self referencing entities in entity framework? -


itemprop = "text">

Some of the institutions have 4 audit properties on them in their application:

  When the public virtual date time was added {get; Set; } Public Virtual Date Time? Updated when {get; Set; } Public Virtual User AddBy {get; Set; } Public Virtual User Updated {Received; Set; }  

I am using a code for the first time and am using the following extension method to map user properties:

  public Fixed Zero MapAuditFields & lt; T & gt; (This EntityTypeConfiguration & lt; t & gt; configuration) where T: class, IAuditable {configuration.HasOptional & lt; Users & gt; (D = & gt; e.AddedBy) .withOptionalDependent () .map (a => a.MapKey ("AddedByUserId")); Configuration. Hesopation & lt; Users & gt; (E => E. Update). With Optibilisent (). (A => M.M.MK ("UpdateBUIRID")); }  

This is working fine in most cases, but not on user class, of course there is a recursive relationship with it when I try to customize host table column names in this scenario I have been told that there is a bug in the organization's framework, for example:

and

I get the error "Sequence contains more than one matching element".

Does anyone know that this institution has been fixed in Structure 6?

Many thanks.

After

use withmany () instead of WithOptionalDependent () If a user can add or update many other users, such as

class:

  public class user {public integer id {get; Set; } Public Virtual User AddBy {get; Set; } Public Virtual User Updated {Received; Set; }}  

Fluent API Call:

  modelBuilder.Entity & lt; Users & gt; () .HasOptional (U = & gt; u.AddedBy) .WithMany () .mp (fkamc = & gt; fkamc.MapKey ("Added User ID")); ModelBuilder.Entity & LT; Users & gt; () .HasOptional (U = & gt; u.UpdatedBy) .withMany () .map (fkamc = & gt; fkamc.MapKey ("UpdatedByUserId"));  

Result:

result


Comments