[英]c# foreign key annotation with Type (not String)
我看你可以用
[ForeignKeyAttribute("foreignKeyName")]
但是我想知道是否有一個類型而不是字符串 ?
為了更安全的重構...
還是使用字符串有很好的用途?
如果您想知道何時更改名稱或其他更改(應在編譯錯誤中更改其值),則最好使用Fluent Api
您能否創建自己的自定義屬性,該屬性從外鍵屬性繼承並重載構造函數? 我尚未測試過,但您可以嘗試執行以下操作:
public class ForeignKeyTypeAttribute : ForeignKeyAttribute
{
public ForeignKeyTypeAttribute(string name) : base(name)
{ }
public ForeignKeyTypeAttribute(Type t) : base(t.GetType().Name)
{ }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.