Je le code suivant:EntityFramework FluentAPI problème Maping
namespace DynamicAssembly {
using System;
using System.Collections.Generic;
using System.Collections;
using System.Data.Objects;
using System.Data.EntityClient;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using System.Data.Entity.Infrastructure;
[Table("eElementDef1")]
public class ElementDef1 {
public int pID { get; set; }
public virtual ElementDef2 Pointer_EntityDef2 { get; set; }
public virtual ElementDef1 Poniter_EntityDef1 { get; set; }
public ElementDef1() {
}
}
[Table("eElementDef2")]
public class ElementDef2 {
public int pID { get; set; }
public String Name { get; set; }
public ElementDef2() {
}
}
public class Context : System.Data.Entity.DbContext {
public DbSet<ElementDef1> ElementDef1
{
get;set;
}
public DbSet<ElementDef2> ElementDef2
{
get;set;
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ElementDef1>().HasKey(c => c.pID);
modelBuilder.Entity<ElementDef1>().HasRequired(p => p.Pointer_EntityDef2)
.WithMany()
.IsIndependent()
.Map(m => m.MapKey(p => p.pID, "Pointer_EntityDef2"));
modelBuilder.Entity<ElementDef1>().HasRequired(p => p.Poniter_EntityDef1)
.WithMany()
.IsIndependent()
.Map(m => m.MapKey(p => p.pID, "Poniter_EntityDef1"));
modelBuilder.Entity<ElementDef2>().HasKey(c => c.pID);
}
public Context() :
base("DynamicDefinitionConnection") {
}
}
}
le problème avec ce mappage modelBuilder.Entity() HasRequired (p => p.Pointer_EntityDef2) .WithMany() .IsIndependent.() .Map (m => m.MapKey (p => p.pID, "Pointer_EntityDef2"));
Le db ne respecte pas de convention, le FK n'est pas Pointer_EntityDef2pId Est-il possible que dans ma classe d'avoir seulement 1 propriété (Pointer_EntityDef2 de type EntityDef2) au lieu de 1 propriété pour l'id et un pour l'objet (ce on fonctionne bien), et la propriété d'avoir le nom FK? Et comment devrait ressembler la cartographie?