给定这个模型课
public class MyClass
{
[Key]
public uint MyObjectId { get; set; }
public long Param1 { get; set; }
public string Param2 { get; set; }
}
如何基于[Key]
注释以编程方式识别主键参数?
在这种情况下 MyObjectId
您可以使用反射。
public class MyClass
{
[Key]
public uint MyObjectId { get; set; }
public long Param1 { get; set; }
public string Param2 { get; set; }
}
void Main()
{
var properties = typeof(MyClass).GetProperties()
.Where(prop => prop.IsDefined(typeof(KeyAttribute), false));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句