I need to join the current entity to multiple legacy tables. However, it
appears that the joins are overriding each other's table name / schema name
/ key column properties (ends up being the last join that is defined, it's
property values would be used for other joins). Does anyone know of a
workaround for it?
Example: The following would generate this SQL statement on creation of a
new User for the first join (notice the insert is based on the first join
property, but it picks up the schema name / table name / key column of the
second join):
* exec sp_executesql N'INSERT INTO Legacy2.UserLegacy2 (Legacy1Name,
Legacy2_Id) VALUES (@p0, @p1)',N'@p0 nvarchar(4000),@p1
uniqueidentifier',@p0=N'legacy1
test',@p1='FC3DFFFF-FB43-4632-BC05-A0DE0108C096'*
public class User
{
public virtual Guid Id { get; set; }
public virtual string ClrType { get; set; }
public virtual string Name { get; set; }
public virtual string Legacy1Name { get; set; }
public virtual string Legacy2Name { get; set; }
public virtual DateTimeOffset LastModifiedOn { get; set; }
}
public class CustomUserMapping : ClassMapping<User>
{
public CustomUserMapping()
{
this.Schema("Security1");
this.Table("User1");
this.Id(x => x.Id, idMap =>
{
idMap.Column("Id");
idMap.Generator(Generators.GuidComb);
});
this.Discriminator(discrim =>
{
discrim.Column(colMap =>
{
colMap.Name("ClrType");
colMap.Length(256);
colMap.SqlType("varchar(256)");
});
});
this.Version(x => x.LastModifiedOn, versionMapping =>
{
versionMapping.Column(colMap =>
{
colMap.Name("LastModifiedOn");
colMap.SqlType("datetimeoffset(7)");
});
versionMapping.Type(new
NHibernate.Type.DateTimeOffsetType());
});
this.Join("UserLegacy1", (x) =>
{
x.Table("UserLegacy1");
x.Schema("Legacy1");
x.Key((z) =>
{
z.Column("Legacy_Id");
});
x.Property(z => z.Legacy1Name, mapTo =>
{
mapTo.Column("Legacy1Name");
});
});
this.Join("UserLegacy2", (x) =>
{
x.Table("UserLegacy2");
x.Schema("Legacy2");
x.Key((z) =>
{
z.Column("Legacy2_Id");
});
x.Property(z => z.Legacy2Name, mapTo =>
{
mapTo.Column("Legacy2Name");
});
});
}
}
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/nhusers/-/wZtB0DzD-f4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.