Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Fluent API and keys from additional property class does not work

$
0
0

Hello,

can someone please help me with the following problem:

I would like to store the class "MyPerson" in a single table with the rows "Name, IdPart1, IdPart2" and use IdPart1 and IdPart2 as the key for MyPerson. I do not know how to do it.
Example:

class MyPerson
  property MyId MyId{get;set}
  property string Name
class MyId
  string IdPart1
  string IdPart2

My Fluent API:

modelBuilder.Entity<Person>().ToTable("MyTable")
modelBuilder.CompleyType<MyId>().Property(p=>p.IdPart1).HasColumName("Part1");
modelBuilder.CompleyType<MyId>().Property(p=>p.IdPart2).HasColumName("Part2");

Now my table needs the key (this does not work):

modelBuilder.Entity<Person>().HasKey(p=>new {p.MyId.IdPart1, p.MyId.IdPart2})

Any idea how to manage it with the fluent api!?

Thank you very much!

Stephan


Viewing all articles
Browse latest Browse all 1698

Trending Articles



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