Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions EntityFramework.MappingAPI.Test/App.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>

<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="TestContext" connectionString="Data Source=.\sqlexpress; Initial Catalog=ef_mapping_test;uid=ef_mapping_test;password=ef_mapping_testx;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
<add name="TestContext" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=ef_mapping_test;Integrated Security=SSPI;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
<!--<add name="TestContext" connectionString="Data Source=.\sqlexpress; Initial Catalog=ef_mapping_test;uid=ef_mapping_test;password=ef_mapping_testx;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />-->
<add name="efmapping_testEntities" connectionString="metadata=res://*/DbFirst.TestModel.csdl|res://*/DbFirst.TestModel.ssdl|res://*/DbFirst.TestModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(localdb)\v11.0;initial catalog=efmapping_test;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class AWorkerTPH : EmployeeTPH
public class ManagerTPH : EmployeeTPH
{
public string Rank { get; set; }
public int? RefId { get; set; }
public int? RefIdNullable { get; set; }
public virtual ICollection<AWorkerTPH> Henchmen { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.ComponentModel.DataAnnotations;

namespace EntityFramework.MappingAPI.Test.CodeFirst.Domain
{
public abstract class FlatInheritenceBase
{

[Key]
public virtual Guid Id { get; set; } = Guid.NewGuid();
public DateTime DateTime { get; set; }
public string String { get; set; }
public int Int { get; set; }
}


public class FiA : FlatInheritenceBase
{
public virtual string StringA { get; set; }
}

public class FiB : FlatInheritenceBase
{
public virtual string StringB { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EntityFramework.MappingAPI.Test.CodeFirst.Domain
{
public abstract class MultipleInheritenceBase
{

[Key]
public virtual Guid Id { get; set; } = Guid.NewGuid();
public DateTime DateTime { get; set; }
public string String { get; set; }
public int Int { get; set; }
}

public class MiA:MultipleInheritenceBase
{
public Guid? MiRefARefId { get; set; }
[ForeignKey(nameof(MiRefARefId))]
public virtual MiRefA MiRefA { get; set; }
}

public class MiB : MiA
{
public Guid? MiRefBRefId { get; set; }
[ForeignKey(nameof(MiRefBRefId))]
public virtual MiRefB MiRefB { get; set; }
}

public class MiC : MiB
{
public Guid? MiRefCRefId { get; set; }
[ForeignKey(nameof(MiRefCRefId))]
public virtual MiRefC MiRefC { get; set; }
}

public class MiRefA
{
[Key]
public virtual Guid Id { get; set; } = Guid.NewGuid();
[InverseProperty(nameof(MiA.MiRefA))]
public virtual ICollection<MiA> MiAs { get; set; }
}

public class MiRefB
{
[Key]
public virtual Guid Id { get; set; } = Guid.NewGuid();
[InverseProperty(nameof(MiB.MiRefB))]
public virtual ICollection<MiB> MiBs { get; set; }
}

public class MiRefC
{
[Key]
public virtual Guid Id { get; set; } = Guid.NewGuid();
[InverseProperty(nameof(MiC.MiRefC))]
public virtual ICollection<MiC> MiCs { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using EntityFramework.MappingAPI.Test.CodeFirst.Domain.ComplexTypes;

namespace EntityFramework.MappingAPI.Test.CodeFirst.Domain
{
public class TestUserWithSecondAddress : EntityWithTypedId<Guid>
{
public Contact Contact { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName { get { return string.Format("{0} {1}", this.FirstName, this.LastName); } }
// complex type must be the last member
public Address Address { get; set; }
}
}
235 changes: 235 additions & 0 deletions EntityFramework.MappingAPI.Test/CodeFirst/MappingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,241 @@ public void Entity_ComplextType_WhereComplexTypeIsLastProperty()
}
}

[Test]
public void Entity_ComplextType_WhereComplexIsInsideTypeAndAlsoIsLastProperty()
{
using (var ctx = new TestContext())
{
var map = ctx.Db<TestUserWithSecondAddress>();


map.Prop(x => x.Id)
.HasColumnName("Id")
.IsPk()
.IsFk(false)
.IsNavigationProperty(false);

map.Prop(x => x.FirstName)
.HasColumnName("Name")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false)
.MaxLength(NvarcharMax);

map.Prop(x => x.LastName)
.HasColumnName("LastName")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false)
.MaxLength(NvarcharMax);

map.Prop(x => x.Contact.PhoneNumber)
.HasColumnName("Contact_PhoneNumber")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false)
.MaxLength(NvarcharMax);

map.Prop(x => x.Contact.Address.Country)
.HasColumnName("Contact_Address_Country")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false)
.MaxLength(NvarcharMax);

map.Prop(x => x.Contact.Address.County)
.HasColumnName("Contact_Address_County")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false)
.MaxLength(NvarcharMax);

map.Prop(x => x.Contact.Address.City)
.HasColumnName("Contact_Address_City")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false)
.MaxLength(NvarcharMax);

map.Prop(x => x.Contact.Address.PostalCode)
.HasColumnName("Contact_Address_PostalCode")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false)
.MaxLength(NvarcharMax);

map.Prop(x => x.Contact.Address.StreetAddress)
.HasColumnName("Contact_Address_StreetAddress")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false)
.MaxLength(NvarcharMax);
#if !NET40
var propertyPropertyMap = map.Prop(x => x.Contact.Address.Location);
propertyPropertyMap
.HasColumnName("Contact_Address_Location")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false);

Console.WriteLine(propertyPropertyMap.DefaultValue);
Console.WriteLine(propertyPropertyMap.FixedLength);
Console.WriteLine(propertyPropertyMap.MaxLength);
Console.WriteLine(propertyPropertyMap.Precision);
Console.WriteLine(propertyPropertyMap.Scale);
Console.WriteLine(propertyPropertyMap.Type);
Console.WriteLine(propertyPropertyMap.Unicode);

var shapePropertyMap = map.Prop(x => x.Contact.Address.Shape);
shapePropertyMap
.HasColumnName("Contact_Address_Shape")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false);

Console.WriteLine(shapePropertyMap.DefaultValue);
Console.WriteLine(shapePropertyMap.FixedLength);
Console.WriteLine(shapePropertyMap.MaxLength);
Console.WriteLine(shapePropertyMap.Precision);
Console.WriteLine(shapePropertyMap.Scale);
Console.WriteLine(shapePropertyMap.Type);
Console.WriteLine(shapePropertyMap.Unicode);
#endif
map.Prop(x => x.Address.Country)
.HasColumnName("Address_Country")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false)
.MaxLength(NvarcharMax);

map.Prop(x => x.Address.County)
.HasColumnName("Address_County")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false)
.MaxLength(NvarcharMax);

map.Prop(x => x.Address.City)
.HasColumnName("Address_City")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false)
.MaxLength(NvarcharMax);

map.Prop(x => x.Address.PostalCode)
.HasColumnName("Address_PostalCode")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false)
.MaxLength(NvarcharMax);

map.Prop(x => x.Address.StreetAddress)
.HasColumnName("Address_StreetAddress")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false)
.MaxLength(NvarcharMax);
#if !NET40
propertyPropertyMap = map.Prop(x => x.Address.Location);
propertyPropertyMap
.HasColumnName("Address_Location")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false);

Console.WriteLine(propertyPropertyMap.DefaultValue);
Console.WriteLine(propertyPropertyMap.FixedLength);
Console.WriteLine(propertyPropertyMap.MaxLength);
Console.WriteLine(propertyPropertyMap.Precision);
Console.WriteLine(propertyPropertyMap.Scale);
Console.WriteLine(propertyPropertyMap.Type);
Console.WriteLine(propertyPropertyMap.Unicode);

shapePropertyMap = map.Prop(x => x.Address.Shape);
shapePropertyMap
.HasColumnName("Address_Shape")
.IsPk(false)
.IsFk(false)
.IsNavigationProperty(false);

Console.WriteLine(shapePropertyMap.DefaultValue);
Console.WriteLine(shapePropertyMap.FixedLength);
Console.WriteLine(shapePropertyMap.MaxLength);
Console.WriteLine(shapePropertyMap.Precision);
Console.WriteLine(shapePropertyMap.Scale);
Console.WriteLine(shapePropertyMap.Type);
Console.WriteLine(shapePropertyMap.Unicode);
#endif


}
}

[Test]
public void Entity_TPH_MultipleInheritence()
{
using(var ctx = GetContext())
{
var map = ctx.Db<MultipleInheritenceBase>();
map.Prop(x => x.Id).IsPk().IsFk(false).HasColumnName("Id").IsNavigationProperty(false);
map.Prop(x => x.DateTime).HasColumnName("DateTime").IsNavigationProperty(false);
map.Prop(x => x.String).HasColumnName("String").IsNavigationProperty(false);
map.Prop(x => x.Int).HasColumnName("Int").IsNavigationProperty(false);

var mapA = ctx.Db<MiA>();
mapA.Prop(x => x.Id).IsPk().IsFk(false).HasColumnName("Id").IsNavigationProperty(false);
mapA.Prop(x => x.DateTime).HasColumnName("DateTime").IsNavigationProperty(false);
mapA.Prop(x => x.String).HasColumnName("String").IsNavigationProperty(false);
mapA.Prop(x => x.Int).HasColumnName("Int").IsNavigationProperty(false);
mapA.Prop(x => x.MiRefARefId).HasColumnName("MiRefARefId").IsNavigationProperty(false);

var mapB = ctx.Db<MiB>();
mapB.Prop(x => x.Id).IsPk().IsFk(false).HasColumnName("Id").IsNavigationProperty(false);
mapB.Prop(x => x.DateTime).HasColumnName("DateTime").IsNavigationProperty(false);
mapB.Prop(x => x.String).HasColumnName("String").IsNavigationProperty(false);
mapB.Prop(x => x.Int).HasColumnName("Int").IsNavigationProperty(false);
mapB.Prop(x => x.MiRefARefId).HasColumnName("MiRefARefId").IsNavigationProperty(false);
mapB.Prop(x => x.MiRefBRefId).HasColumnName("MiRefBRefId").IsNavigationProperty(false);

var mapC = ctx.Db<MiC>();
mapC.Prop(x => x.Id).IsPk().IsFk(false).HasColumnName("Id").IsNavigationProperty(false);
mapC.Prop(x => x.DateTime).HasColumnName("DateTime").IsNavigationProperty(false);
mapC.Prop(x => x.String).HasColumnName("String").IsNavigationProperty(false);
mapC.Prop(x => x.Int).HasColumnName("Int").IsNavigationProperty(false);
mapC.Prop(x => x.MiRefARefId).HasColumnName("MiRefARefId").IsNavigationProperty(false);
mapC.Prop(x => x.MiRefBRefId).HasColumnName("MiRefBRefId").IsNavigationProperty(false);
mapC.Prop(x => x.MiRefCRefId).HasColumnName("MiRefCRefId").IsNavigationProperty(false);
}
}

[Test]
public void Entity_TPH_FlatInheritence()
{
using (var ctx = GetContext())
{
var map = ctx.Db<FlatInheritenceBase>();
map.Prop(x => x.Id).IsPk().IsFk(false).HasColumnName("Id").IsNavigationProperty(false);
map.Prop(x => x.DateTime).HasColumnName("DateTime").IsNavigationProperty(false);
map.Prop(x => x.String).HasColumnName("String").IsNavigationProperty(false);
map.Prop(x => x.Int).HasColumnName("Int").IsNavigationProperty(false);

var mapA = ctx.Db<FiA>();
mapA.Prop(x => x.Id).IsPk().IsFk(false).HasColumnName("Id").IsNavigationProperty(false);
mapA.Prop(x => x.DateTime).HasColumnName("DateTime").IsNavigationProperty(false);
mapA.Prop(x => x.String).HasColumnName("String").IsNavigationProperty(false);
mapA.Prop(x => x.Int).HasColumnName("Int").IsNavigationProperty(false);
mapA.Prop(x => x.StringA).HasColumnName("StringA").IsNavigationProperty(false);

var mapB = ctx.Db<FiB>();
mapB.Prop(x => x.Id).IsPk().IsFk(false).HasColumnName("Id").IsNavigationProperty(false);
mapB.Prop(x => x.DateTime).HasColumnName("DateTime").IsNavigationProperty(false);
mapB.Prop(x => x.String).HasColumnName("String").IsNavigationProperty(false);
mapB.Prop(x => x.Int).HasColumnName("Int").IsNavigationProperty(false);
mapB.Prop(x => x.StringB).HasColumnName("StringB").IsNavigationProperty(false);
}
}


[Test]
public void Entity_TPT_WorkerTPT()
{
Expand Down
Loading