c# - 您可以在 C# 和 Entity Framework 中访问类的 Scaffold 属性吗?

标签 c# entity-framework

<分区>

例如,如果你有

 public class user 
 {
    public string x { get; set; }

    [ScaffoldColumn(false)]
    public string y { get; set; }
 }

无论如何,当我查看实体以确定 y 是否确实将脚手架列设置为 false 时?我试过像这样以编程方式循环(伪代码):

foreach(var prop in user.GetProperties())
{  
    var attributes = prop.Attributes;
}

但似乎没有属性属性或指示属性(在本例中为 y)是否为脚手架列。

最佳答案

您可以获得所有具有 [ScaffoldColumn(false)] 的属性,如下所示:

var props = obj.GetType()
           .GetProperties(BindingFlags.Instance | BindingFlags.Public)
           .Select(p => new
           {
               Property = p,
               Attribute = p.GetCustomAttribute<ScaffoldColumnAttribute>()
           })
           .Where(p => p.Attribute != null && p.Attribute.Scaffold == false)
           .ToList();

关于c# - 您可以在 C# 和 Entity Framework 中访问类的 Scaffold 属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20981500/

相关文章:

c# - 如何在不使用 TransactionScope 的情况下使用 EF4 Code First CTP5 分配事务?

sql-server - Windows Azure SQL数据库-“身份自动增加”列会跳过值

entity-framework - 我可以强制使用 Entity Framework 的多重性/关联吗?

c# - 在数据库上下文中执行 Elastic Sc​​ale 多分片查询

c# - 增加或更新 Entity Framework 的数量

c# - 样式设置的工具提示不起作用

c# - 使用 c# 在 winrt 中使用 SQLiteConnection 的问题?

c# - 将内存流对象序列化为字符串

c# - 调试器进入条件为假的 if() block

c# - 如何动态使用 SqlFunctions.PatIndex