I tried a INSERT directly to the database
Code: Select all
INSERT INTO Adresse VALUES (NEWID(), 'Main Road 15', '20095', 'Hamburg','{FE5852D8-393A-4DEF-850F-50DEC50EEAE2}', GETDATE())
Same error.
Now I investigated the created Foreign Keys. There are two on the table [Adresse]. The first maps [Adresse].[KundeId] to [Kunde].[Id] and the second maps
[Adresse].[Id] with [Kunde].[Id] which does not make sense.
Why this second FK is created?
Here are the three config files created:
BaseClassConfiguration.cs
Code: Select all
//------------------------------------------------------------------------------
// This is auto-generated code.
//------------------------------------------------------------------------------
// This code was generated by Devart Entity Developer tool using Entity Framework DbContext template.
// Code is generated on: 22.07.2017 09:52:42
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//------------------------------------------------------------------------------
using System.Data.Entity.ModelConfiguration;
namespace Entities.Mapping
{
public partial class BaseClassConfiguration : EntityTypeConfiguration<BaseClass>
{
public BaseClassConfiguration()
{
this
.HasKey(p => p.Id)
.Map(tpc => { });
// Properties:
this
.Property(p => p.Id)
.IsRequired()
.HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.None);
OnCreated();
}
partial void OnCreated();
}
}
KundeConfiguration.cs
Code: Select all
//------------------------------------------------------------------------------
// This is auto-generated code.
//------------------------------------------------------------------------------
// This code was generated by Devart Entity Developer tool using Entity Framework DbContext template.
// Code is generated on: 22.07.2017 09:52:42
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//------------------------------------------------------------------------------
using System.Data.Entity.ModelConfiguration;
namespace Entities.Mapping
{
public partial class KundeConfiguration : EntityTypeConfiguration<Kunde>
{
public KundeConfiguration()
{
this
.Map(tpc =>
{
tpc.MapInheritedProperties();
tpc.ToTable("Kunde", "dbo");
});
// Properties:
this
.Property(p => p.Nr)
.HasColumnType("int");
this
.Property(p => p.Name)
.HasMaxLength(32)
.HasColumnType("varchar");
// Association:
this
.HasMany(p => p.Adressen)
.WithOptional(c => c.Kunde)
.HasForeignKey(p => p.KundeId)
.WillCascadeOnDelete(false);
OnCreated();
}
partial void OnCreated();
}
}
AdresseConfiguration.cs
Code: Select all
//------------------------------------------------------------------------------
// This is auto-generated code.
//------------------------------------------------------------------------------
// This code was generated by Devart Entity Developer tool using Entity Framework DbContext template.
// Code is generated on: 22.07.2017 09:52:42
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//------------------------------------------------------------------------------
using System.Data.Entity.ModelConfiguration;
namespace Entities.Mapping
{
public partial class AdresseConfiguration : EntityTypeConfiguration<Adresse>
{
public AdresseConfiguration()
{
this
.Map(tpc =>
{
tpc.MapInheritedProperties();
tpc.ToTable("Adresse", "dbo");
});
// Properties:
this
.Property(p => p.Strasse)
.HasMaxLength(32)
.HasColumnType("varchar");
this
.Property(p => p.PLZ)
.HasMaxLength(6)
.HasColumnType("varchar");
this
.Property(p => p.Ort)
.HasMaxLength(32)
.HasColumnType("varchar");
this
.Property(p => p.KundeId)
.HasColumnType("uniqueidentifier");
OnCreated();
}
partial void OnCreated();
}
}
What I am doing wrong, where is the reason to create this weired FK or how I can avoid it?
Why a BaseClassConfig is created? I do not want this, the inheritance modifier is 'abstract'.
I cannot find my mistake.