![](/img/trans.png)
[英]Get All Columns Names in the selected table provided the class names are passed as a String using Entity Framework 4.0
[英]How to get the Names of all Columns in a Linq to Entity Datamodel (with one table)?
我有一個實體,基本上是一個數據模型。
該模型具有多個“列”
ID, names, addresses, zip codes
所有這些列均填充有數據。
為了“連接”到我的實體框架,我正在使用
using ( EntityFrameworkEntity entites = new EntityFrameworkEntity() )
{
}
那么,如何在字符串數組中獲取這些列的名稱呢?
結果應如下所示:
StringArray[0] = "ID"
StringArray[1] = "names"
StringArray[2] = "addresses"
.
.
.
我是初學者,對您的幫助將不勝感激
嘗試這個:
IEnumerable<FieldList> properties = from p in typeof(T).GetProperties()
where (from a in p.GetCustomAttributes(false)
where a is EdmScalarPropertyAttribute
select true).FirstOrDefault()
select new FieldList
{
FieldName = p.Name,
FieldType = p.PropertyType,
FieldPK = p.GetCustomAttributes(false).Where(a => a is EdmScalarPropertyAttribute && ((EdmScalarPropertyAttribute)a).EntityKeyProperty).Count() > 0
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.