c# - FluentNhibernate mapping when having two primary keys -
i use fluent nhibernate c# application , have basic question. know nhibernate mapping class should when have multiple primary keys.
here example showing how implement mapping , other model classes:
create table students( id int not null, name varchar (20) not null, age int not null, primary key (id) );
public class students { public virtual int id { get; set; } public virtual string name { get; set; } public virtual int age { get; set; } } public class studentmap : classmap<students> { public achivementmastermap() { id(x => x.id).column("id"); map(x => x.name).column("name"); map(x => x.age).column("age"); table("students"); } }
let's assume have 2 primary keys on student table this
create table students( id int not null, name varchar (20) not null, age int not null, primary key (id,name) );
so how write mapping class above table?
you don't have 2 primary keys, appear have composite primary key. think can use fluent nhibernate compositeid - this:
public class studentmap : classmap<students> { public studentmap() { compositeid() .keyproperty(x => x.name, "id") .keyproperty(x => x.name, "name"); ...
Comments
Post a Comment