我如何从LINQ模型中获取列名? [英] How would I get the column names from a Model LINQ?

查看:78
本文介绍了我如何从LINQ模型中获取列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找从模型返回的列名的列表.任何人都知道该怎么做,任何帮助将不胜感激.

I am looking to get a list of the column names returned from a Model. Anyone know how this would be done, any help would be greatly appreciated.

示例代码:

var project = db.Projects.Single(p => p.ProjectID.Equals(Id));

此代码将返回Projects对象,我将如何获得此Model中所有列名称的列表.

This code would return the Projects object, how would I get a list of all the column names in this Model.

谢谢

推荐答案

对不起,我没有LINQ的工作经验.

I am sorry, I don't have working experience with LINQ.

这纯粹是基于MSDN.

This is purely based on looking at MSDN.

DataContext具有Mapping属性,该属性返回 MemberInfo 参数.您将必须在Projects对象上使用反射以获得MemberInfo对象.
返回 MetaDataMember 实例GetDataMember提供的所有东西都可以满足您的需求.

DataContext has a Mapping property, which returns an instance of MetaModel.
MetaModel has GetMetaType, which takes a Type. In your case it could be typeof(Project).
GetMetaType returns a MetaType which has the GetDataMember method, which takes a MemberInfo parameter. You will have to use reflection on your Projects object to get the MemberInfo object.
The MetaDataMember instance returned by GetDataMember should have all the things, you need.

我希望我朝着正确的方向(纯粹着眼于MSDN和遍历)

I hope I am somewhat in right direction (purely looking at MSDN & traversing)

这篇关于我如何从LINQ模型中获取列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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