Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取所选表中的所有列名称,前提是使用Entity Framework 4.0将类名作为字符串传递_C#_Asp.net_Entity Framework_Linq To Entities - Fatal编程技术网

C# 获取所选表中的所有列名称,前提是使用Entity Framework 4.0将类名作为字符串传递

C# 获取所选表中的所有列名称,前提是使用Entity Framework 4.0将类名作为字符串传递,c#,asp.net,entity-framework,linq-to-entities,C#,Asp.net,Entity Framework,Linq To Entities,我想获取所选数据库中所有列的名称,前提是要获取的列的表的名称在字符串数组中,并且可以动态更改 我有一个代码,在该代码中,我只能获取特定表中所有列的名称: var properties = from p in typeof(EntityAttribute).GetProperties() where (from a in p.GetCustomAttributes(false)

我想获取所选数据库中所有列的名称,前提是要获取的列的表的名称在字符串数组中,并且可以动态更改

我有一个代码,在该代码中,我只能获取特定表中所有列的名称:

 var properties = from p in typeof(EntityAttribute).GetProperties()
                                                    where (from a in p.GetCustomAttributes(false)
                                                           where a is EdmScalarPropertyAttribute
                                                           select true).FirstOrDefault()
                                                    select new 
                                                    {
                                                        FieldName = p.Name,
                                                        FieldType = p.PropertyType,
                                                        FieldPK = p.GetCustomAttributes(false).Where(a => a is EdmScalarPropertyAttribute && ((EdmScalarPropertyAttribute)a).EntityKeyProperty).Count() > 0
                                                    };
EntityAttribute是列的名称

问题是这个类名EntityAttribute是一个类。我想从字符串数组中传递这个类名

示例:我有一个字符串数组,其名称为三个表:

现在我想通过传递字符串中的类名来迭代上面给出的代码


我应该如何传递它?

您可以使用
GetType

Type type = Type.GetType("YourApplication.Namespace.EntityAttribute");

您是否使用了完全限定字符串
YourApplication.Namespace.EntityAttribute
例如,更新了我的回答,因为我犯了错误。谢谢你,真是太棒了。很高兴我能帮忙!