2016-04-27 8 views
0

EntitySpaces( "ES")ORMに経験がない、または現在使用されていない場合、この質問はあなたのためのものではありません。EntitySpaceに遅延読み込み列を追加するにはどうすればよいですか?

私は4年後に私の注意を必要とする10歳のアプリケーションがあります。私のアプリケーションでは、EntitySpacesという名前のないORMが使用されています。これを読んでいれば、あなたは経験を持っているのでしょうか、それとも多分まだ使用していると思います!現時点では別のORMに切り替えることはできませんので、この作業を行う方法を見つける必要があります。

最後に、私のアプリケーションで最後に積極的に作業していた時点(ESバージョン2012-09-30)まで、EntitySpaces(「ES」)は基礎となるADO.netバックエンドで大幅な変更を行っています。私はその後、私はlazyloadできるように、最初の選択にロードされなかったプロパティをオーバーライド

_products = new ProductCollection(); 
_products.Query.SelectAllExcept(_products.Query.ImageData); 
_products.LoadAll(); 

:私は助けを求めていたシナリオは、エンティティのコレクションは、列のサブセットのみがロードされたときでありますそれらはアクセサーにあります。ここでは、完全に動作するために使用された遅延ロードされたプロパティの例を示します。

public override byte[] ImageData 
{ 
    get 
    { 
     bool rowIsDirty = base.es.RowState != DataRowState.Unchanged; 

     // Check if we have loaded the blob data 
     if(base.Row.Table != null && base.Row.Table.Columns.Contains(ProductMetadata.ColumnNames.ImageData) == false) 
     { 
      // add the column before we can save data to the entity 
      this.Row.Table.Columns.Add(ProductMetadata.ColumnNames.ImageData, typeof(byte[])); 
     } 

     if(base.Row[ProductMetadata.ColumnNames.ImageData] is System.DBNull) 
     { 
      // Need to load the data 
      Product product = new Product(); 
      product.Query.Select(product.Query.ImageData).Where(product.Query.ProductID == base.ProductID); 
      if(product.Query.Load()) 
      { 
       if (product.Row[ProductMetadata.ColumnNames.ImageData] is System.DBNull == false) 
       { 
        base.ImageData = product.ImageData; 

        if (rowIsDirty == false) 
        { 
         base.AcceptChanges(); 
        } 
       } 
      } 
     } 

     return base.ImageData; 
    } 
    set 
    { 
     base.ImageData = value; 
    } 
} 

私は基礎となるのDataTableのDataColumnコレクションに列を追加する場所興味深い部分は次のとおりです。

this.Row.Table.Columns.Add(ProductMetadata.ColumnNames.ImageData, typeof(byte[])); 

私が更新するとき、私はそのアクセサからすべてのADO.net関連のものをコメントアウトしなければなりませんでしたES(バージョン2012-09-30)の現行(およびオープンソース)エディションです。それは、「ImageDataを」欄が正しく設定されていないことを意味し、私が変更されたときには、データと、私は次のエラーが表示されたエンティティを保存しようとする試みです:

Column 'ImageData' does not belong to table .

私はESソースを覗き数日費やしてきました実験を行って、エンティティを後退させるためにDataTableを使用するのではなく、代わりに「esSmartDictionary」を使用しているように見えます。

私の質問は、新しいバージョンのESで使用されていたのと同じ遅延ロードされた動作を実現するための既知のサポートされた方法がありますか? ORMにエンティティバッキングストアに追加するように伝えることで、最初の選択に含まれていないプロパティ(つまり列)をどこで更新できますか?

答えて

0

ESがどのように更新を使用するDataTableを構築するかを分析した後、初期選択(すなわちロード)操作に含まれていない列がesEntityCollectionBase.SelectedColumns辞書に追加される必要があることが明らかになりました。これを処理する次のメソッドを追加しました。

/// <summary> 
/// Appends the specified column to the SelectedColumns dictionary. The selected columns collection is 
/// important as it serves as the basis for DataTable creation when updating an entity collection. If you've 
/// lazy loaded a column (i.e. it wasn't included in the initial select) it will not be automatically 
/// included in the selected columns collection. If you want to update the collection including the lazy 
/// loaded column you need to use this method to add the column to the Select Columns list. 
/// </summary> 
/// <param name="columnName">The lazy loaded column name. Note: Use the {yourentityname}Metadata.ColumnNames 
/// class to access the column names.</param> 
public void AddLazyLoadedColumn(string columnName) 
{ 
    if(this.selectedColumns == null) 
    { 
     throw new Exception(
      "You can only append a lazy-loaded Column to a partially selected entity collection"); 
    } 

    if (this.selectedColumns.ContainsKey(columnName)) 
    { 
     return; 
    } 
    else 
    { 
     // Using the count because I can't determine what the value is supposed to be or how it's used. From 
     // I can tell it's just the number of the column as it was selected: if 8 colums were selected the 
     // value would be 1 through 8 - ?? 
     int columnValue = selectedColumns.Count; 
     this.selectedColumns.Add(columnName, columnValue); 
    } 
} 

あなたはこのように、このメソッドを使用します。

public override System.Byte[] ImageData 
{ 
    get 
    { 
     var collection = this.GetCollection(); 
     if(collection != null) 
     { 
      collection.AddLazyLoadedColumn(ProductMetadata.ColumnNames.ImageData); 
     } 
... 

それは誰もがオープンソースEntitySpacesに興味を持っていないことは残念です。私はそれが未来を持っていると思ったら、私はそれに取り組むことができてうれしいですが、それはそうではありません。 :(

私はまだ他のユーザーからのアプローチや洞察に興味があります

関連する問題