엔티티에서 연관성 속성을 정의하고 싶지 않거나 정의 할 수없는 경우 (동적으로 플러그인을로드하는 모듈 식 응용 프로그램과 같이), Fluent API를 사용하여 "가짜"연관을 만들 수 있습니다.
오차드 소스 코드 "ContentItemAlteration"클래스를 참조하십시오. Orchard에서는 ContentItem 엔티티를 다른 테이블에 저장된 ContentPart 레코드와 조인하려고합니다. 각 ContentPart 유형은 모듈에 의해 제공되므로 ContentItem의 소스를 변경하고 각 새 부품 레코드에 대한 연결을 추가하는 것이 어려울 수 있습니다.
/// <summary>
/// Add a "fake" column to the automapping record so that the column can be
/// referenced when building joins accross content item record tables.
/// <typeparam name="TItemRecord">Either ContentItemRecord or ContentItemVersionRecord</typeparam>
/// <typeparam name="TPartRecord">A part record (deriving from TItemRecord)</typeparam>
/// </summary>
class Alteration<TItemRecord, TPartRecord> : IAlteration<TItemRecord> {
public void Override(AutoMapping<TItemRecord> mapping) {
// public TPartRecord TPartRecord {get;set;}
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);
// record => record.TPartRecord
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") // prevent foreign key constraint from ContentItem(Version)Record to TPartRecord
.Unique()
.Not.Insert()
.Not.Update()
.Cascade.All();
}
}
이 코드는 간단하게 사용할 수의 ContentItem에 "일부"연결을 추가하여 CRITERIAS에 조인
는 여기에 내가 오차드 소스에서 얻은 정확한 코드입니다. 예를 들어, "ProductPartRecord"라는 테이블에 저장되어있는 "ProductPart"라는 부분이 있다면, 가짜 속성 "ProductPartRecord"에 ContentItem을 가입시킬 수 있습니다.
그건 그렇고,이 전술은 또한 가짜 관계의 HasMany 측면에도 적용될 수 있지만 내가 생각하는 Fluent 소스를 사용자 정의해야합니다.
Yeap. 나는 그것을 기준으로 사용하고있다. 나는 이런 식으로 뭔가 만들 가능성을 찾고 있어요 : 고객, 고객, 주문 순서, 사용자, 사용자 order.SomeID_1 = customer.Id order.SomeID_2 = user.Id 에서 선택 고객, 주문 I SomeID_xxx 필드에 디자인 타임에 어떤 필드가 들어 있는지 모릅니다. :/ – dariol
좋아, 알았다. HQL은 하나의 옵션 일뿐입니다. – dariol
에 대한 기준 쿼리를 작성할 수 있었습니까? 그렇다면 pls post..adadly 같은 상황에서 메신저 :( – Illuminati