I have 2 entities (Oracle DB Tables).
Between these tables there is no Foreign key. I need to map ProductCsPcsEntity to ProductEntity if ProductEntity.Case_Size = ProductCsPcsEntity.CaseSize.
That means if ProductEntity has Casesize which is in ProductCsPcsEntity than ProductCsPcsEntity row will be saved into the property in ProductEntity, else reference will be null.
There is a relationship (ProductCsPcsEntity) One-To-Many (ProductEntity), but ProductCsPcsEntity has not all Casesizes from ProductEntity (only few - 20 from 60). I want to use something like left join in NHibernate.
public sealed class ProductEntityXXMap : SubclassMap<ProductEntityXX>
{
public ProductEntityXXMap()
{
Map(x => x.CaseSize, "CASE_SIZE");
. . . .
References(x => x.CsPcs, "CASE_SIZE");
DynamicUpdate();
}
}
And
class ProductCsPcsEntityMap : EntityMap<ProductCsPcsEntity>
{
public ProductCsPcsEntityMap()
{
//Id(x => x.Id).GeneratedBy.Assigned();
Table("ProductCsPcsEntity");
Map(x => x.CaseSize, "CASESIZE");
Map(x => x.Pcs, "PCS");
Cache.ReadOnly();
}
}
Is there any solution how to solve this? I use NHibernate v4.0.30319, Oracle DB and .NET 4.
OR
How can I join these tables in maping ?
Join("ProductCsPcsEntity", x =>
{
//x.Fetch.Join().Optional();
x.KeyColumn("CASE_SIZE");
//x.Map(t => t.LeadFramePcs.Pcs).Column("PCS");
x.Map(t => t.LeadFramePcs).Column("CASESIZE");
});
But its join ProductEntityXX.id = ProductCsPcsEntity.casesize
My solution that works:
Map(x => x.Pcs).Formula("(SELECT LF.PCS FROM ProductCsPcsEntity LF WHERE LF.CASE_SIZE = CASE_SIZE)");
it seems that this solution works, but it is not nice