If you do not want or cannot define association properties in your objects (for example, in modular applications that support dynamic loading of plugins), you can still create “fake” associations using the Fluent api.
. Orchard, "ContentItemAlteration". Orchard ContentItem ContentPart, . ContentPart , , (, , ) ContentItem .
, Orchard:
class Alteration<TItemRecord, TPartRecord> : IAlteration<TItemRecord> {
public void Override(AutoMapping<TItemRecord> mapping) {
var name = typeof(TPartRecord).Name;
var dynamicMethod = new DynamicMethod(name, typeof(TPartRecord), null, typeof(TItemRecord));
var syntheticMethod = new SyntheticMethodInfo(dynamicMethod, typeof(TItemRecord));
var syntheticProperty = new SyntheticPropertyInfo(syntheticMethod);
var parameter = Expression.Parameter(typeof(TItemRecord), "record");
var syntheticExpression = (Expression<Func<TItemRecord, TPartRecord>>)Expression.Lambda(
typeof(Func<TItemRecord, TPartRecord>),
Expression.Property(parameter, syntheticProperty),
parameter);
mapping.References(syntheticExpression)
.Access.NoOp()
.Column("Id")
.ForeignKey("none")
.Unique()
.Not.Insert()
.Not.Update()
.Cascade.All();
}
}
"part" ContentItem, . , , "ProductPart", "ProductPartRecord", ContentItem "ProductPartRecord".
, , HasMany , Fluent, .