I want to have a staging table with two foreign keys (like ComposedId). But NHibernate automatically creates an id property.
I have the following classes
public class Lace { public virtual int Id { get; set; } public virtual string Hostname { get; set; } public virtual IList<LaceHasCard> LaceHasCards { get; set; } } public class Card { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual IList<LaceHasCard> LaceHasCards { get; set; } }
and this manually created staging table
public class LaceHasCard { public virtual Card Card { get; set; } public virtual Lace Lace { get; set; } }
<strong> Display
public LaceMapping() { Id(x => x.Id, map => map.Generator(Generators.Native)); Property(x => x.Hostname); Bag(x => x.LaceHasCards, col => { col.Key(k => k.Column("LaceId")); col.Inverse(true); }, r => r.OneToMany()); } public CardMapping() { Id(x => x.Id, map => map.Generator(Generators.Native)); Property(x => x.Name); Bag(x => x.LaceHasCards, col => { col.Key(k => k.Column("CardId")); col.Inverse(true); }, r => r.OneToMany()); }
intermediate table display
public LaceHasCardMapping() { //ComposedId(map => //{ // map.Property(x => x.Card.Id, a => // { // a.Column("CardId"); // }); // map.Property(x => x.Lace.Id, a => // { // a.Column("LaceId"); // }); //}); ManyToOne(x => x.Card, map => { map.Column("CardId"); }); ManyToOne(x => x.Lace, map => { map.Column("LaceId"); }); }
If I create a schema with ComposedId compilation, NHibernate will create the id property in the table.
CREATE TABLE [dbo].[LaceHasCard] ( [id] INT NOT NULL, [CardId] INT NULL, [LaceId] INT NULL, PRIMARY KEY CLUSTERED ([id] ASC), CONSTRAINT [FKDC6D54711CD160AE] FOREIGN KEY ([CardId]) REFERENCES [dbo].[Card] ([Id]), CONSTRAINT [FKDC6D547151F8AF85] FOREIGN KEY ([LaceId]) REFERENCES [dbo].[Lace] ([Id]) );
If I try to create a schema with ComposedId, I get the following error message:
Unable to instantiate mapping class (see InnerException): EmpLaceMgmt.Models.Mappings.LaceHasCardMapping
What would be the proper way to tell NHibernate to create a compiled identifier?