NHibernate Automapperを使用して、次のクラスをマップしたいと思います。
public class AdminUser: Identity, IIdentityWithRoles
{
public virtual IList<Role> Roles { get; set; }
}
問題は、Automapperが、ロールにadminuserIdがあるスキーマ内に多対1の関係を作成することです。しかし、私はこれで多対多になる役割が必要です。注Roleクラスを変更してIListを含めることはできません。これは、別のライブラリにあり、AdminUserの知識がないためです。
私が本当にやりたいのは、このように属性を追加できるようにすることです。
public class AdminUser: Identity, IIdentityWithRoles
{
[ManyToMany]
public virtual IList<Role> Roles { get; set; }
}
これにより、automapperはこれを強制的に実行します。Automapper構成を調整してこの属性を探すことは可能ですか、それともすでにこの仕事をしているFluentNhibernateに組み込まれているものがありますか?
あなたが提供できるどんな助けにも感謝します。
アップデート -
ポインタ(賛成)に感謝しますが、今はここで立ち往生しています:
public class ManyToManyConvention : AttributePropertyConvention<ManyToManyAttribute>
{
protected override void Apply(ManyToManyAttribute attribute, IPropertyInstance instance)
{
How can I now say that this property should be a many to may relationship
}
}
public class ManyToManyAttribute : Attribute
{
}