2011-07-19 6 views
0

私は、SimpleRepositoryが私が探している解決策であると思われるlateとSubSonicのORMを探していました。私自身の属性をSubsonic SimpleRepositoryで使用する

SQLの世代の一部を駆動するために、独自の属性またはSystem.ComponentModelのものを使用する方法はありますか?モデル/ドメインオブジェクトをサードパーティのものからきれいに保ちたい

+0

なぜ-1と

private static bool ColumnIsIgnored(object[] attributes) { foreach (var att in attributes) { if (att.ToString().Equals("SubSonic.SqlGeneration.Schema.SubSonicIgnoreAttribute")) { return true; } } return false; } 

を探す必要があります????? –

答えて

2

これはお勧めできませんが、これを行うことができます。

SubSonics属性(のようなOrmIgnoreの代わりSubSonicIgnore、まだ取得するSubSonic.Core \拡張\ Object.csから、このコードでSubSonic.SqlGeneration.Schema.IClassMappingAttributeまたはSubSonic.SqlGeneration.Schema.IPropertyMappingAttributeまたはSubSonic.SqlGeneration.Schema.IRelationMappingAttribute

ルックを実装する必要があると一致して、独自の属性を作成します。 。

01:あなたの適用実装はあなたがやりたいようにスキーマを変更する必要があります(SubSonicDefaultSettingAttributeから)このような を

public static ITable ToSchemaTable(this Type type, IDataProvider provider) 
    { 

     ... 

     var typeAttributes = type.GetCustomAttributes(typeof(IClassMappingAttribute), false); 

     foreach (IClassMappingAttribute attr in typeAttributes) 
     { 
      if (attr.Accept(result)) 
      { 
       attr.Apply(result); 
      } 
     } 

     ... 

     // Now work with attributes 
     foreach (IPropertyMappingAttribute attr in attributes.Where(x => x is IPropertyMappingAttribute)) 
     { 
      if (attr.Accept(column)) 
      { 
       attr.Apply(column); 
      } 
     } 

     .... 

    } 

を何が起こっているかのアイデア

public void Apply(IColumn column) 
    { 
     column.DefaultSetting = DefaultSetting; 
    } 

あなたは亜音速のソースをチェックアウトし、すべてのカスタム属性をマークする必要があるとして廃止された

[Obsolete("Use OrmIgnore instead", true)] 
[AttributeUsage(AttributeTargets.Property)] 
public class SubSonicIgnoreAttribute : Attribute { } 

あなたが修正する必要があります(インタフェースを使用していない)の属性にはいくつかの直接の言及があります。 。

そして、あなたは、文字列の参照

private static bool ColumnIsIgnored(object[] attributes) 
    { 
     foreach (var att in attributes) 
     { 
      if (att.ToString().EndsWith("OrmIgnoreAttribute")) 
      { 
       return true; 
      } 
     } 

     return false; 
    } 
関連する問題