2016-10-14 3 views
4

私はInsight.DatabaseマイクロORMとして使用しています。私は、次のPOCOクラスの関連付けを行い、結果を1つの行からこれらのオブジェクトにマップする方法があるかどうかを確認したいと考えました。ここでInsight.Database列をオブジェクトにマッピング

public class Rule 
{ 
    public int Id { get; set; } 
    public string Name { get; set; } 
    public RuleDetail Source { get; set; } 
    public RuleDetail Destination { get; set; } 
} 

public class RuleDetail 
{ 
    public int Id { get; set; } 
    public Name { get; set; } 
    public Date DateTime { get; set; } 
    // omitted... 
} 

たちのストアドプロシージャから返される列です:あなたは

public interface IRepo 
{ 
    [Recordset(1, typeof(RuleDetail), into="Source", IsChild=true)] 
    [Recordset(2, typeof(RuleDetail), into="Destination", IsChild=true)] 
    Rule GetFullyPopulatedRuleByIdStoredProcedure(int id); 
} 

を試みることができる

Id 
Name 

// Should map to Source object. 
SourceId 
SourceName 
SourceDateTime 

// Should map to Destination object. 
DestinationId 
DestinationName 
DestinationDateTime 

答えて

0

次の3つのレコードセットを返す必要があります - 最初の[レコードセットを( 0)]はあなたのルールであり、他の2つはソースとデスティネーションを含んでいます。私はこの取り決めをたくさん使っています。それは私にとってうまくいきます。

単一のレコードセットで1行を返す場合は、これを行う方法はわかりません。

1

これは、クエリ側で少し設定することで可能です。属性で可能かどうかは不明です。

var returns = Query.Returns(
    new OneToOne<Rule, RuleDetail, RuleDetail>(
     callback: (rule, source, destination) => { 
      rule.Source = source; 
      rule.Destination = destination; 
     }, 
     columnOverride: new ColumnOverride[] { 
      new ColumnOverride<RuleDetail>("SourceId", "Id"), 
      new ColumnOverride<RuleDetail>("SourceName", "Name"), 
      new ColumnOverride<RuleDetail>("SourceDateTime", "DateTime"), 
      new ColumnOverride<RuleDetail>("DestinationId", "Id"), 
      new ColumnOverride<RuleDetail>("DestinationName", "Name"), 
      new ColumnOverride<RuleDetail>("DestinationDateTime", "DateTime"), 
     }, 
     splitColumns: new Dictionary<Type, string>() { 
      { typeof(Rule), "Id" }, 
      { typeof(RuleDetail), "SourceId" }, 
      { typeof(RuleDetail), "DestinationId" }, 
     } 
    ) 
); 
return Db.Query(procedure, params, returns); 

私は、そのコードのすべてがそれを動作させるために必要とされるかどうかわからないんだけど、それは間違いなくInsight.Databaseで照会がいかに強力で示しています。

関連する問題