如何从Linq.Table< TEntity>获取ColumnAttributes? [英] How do I get the ColumnAttributes from a Linq.Table<TEntity>?

查看:70
本文介绍了如何从Linq.Table< TEntity>获取ColumnAttributes?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从DataContext返回列的属性.

I'm trying to return attributes of columns from my DataContext.

如何提取ColumnAttribute元数据?

How can I pull out the ColumnAttribute meta data?

public class MyDataContext : DataContext
{
    public Table<User> User;
    public MyDataContext(string connection) : base(connection) { }
}

[Table(Name = "User")]
public class User
{
    [Column(IsPrimaryKey = true)]
    public long ID;
    [Column]
    public string FirstName;
    [Column(CanBeNull=false)]
    public string LastName;

    int VersionNumber = 1000;
}

如何访问User对象或Table<User>对象以获取有关列的MetaData(IsPrimaryKey,CanBeNull等)?

How do I access the User object or Table<User> object to get the MetaData (IsPrimaryKey, CanBeNull, etc.) about the columns?

先谢谢了.还在学习...

Thanks in advance. Still learning...

推荐答案

var context = new MyDataContext();
MetaTable userMeta = context.Mapping.GetTable(typeof(User));
var dataMembers = userMeta.RowType.PersistentDataMembers;

从那里,您可以了解各种东西.

From there, you can get to all kinds of stuff.

这篇关于如何从Linq.Table&lt; TEntity&gt;获取ColumnAttributes?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆