开发者

Query Object's elements in c#

开发者 https://www.devze.com 2023-04-01 20:20 出处:网络
I have a problem when i try to ret开发者_高级运维rieve query results from object in c#. I did a linq query that return object element and the i wanna get all elements value in c# (server side)...

I have a problem when i try to ret开发者_高级运维rieve query results from object in c#.

I did a linq query that return object element and the i wanna get all elements value in c# (server side)...

I can't do this and i don't know why!

I tried:

forech(var x in element)
{
  string titolo= x.title.ToString();
}

and

dynamic temp=(dynamic)element;

string titolo=temp.title.ToString();

AND OTHERS....

I can see that the object type is:

{
System.Data.Objects.ObjectQuery<<>f__AnonymousType26<int,string,string,bool?,int?,System.Linq.IQueryable<<>f__AnonymousType25<string>>>>
}

How can i get object's values?

Thanks a lot!


If you're looking for the properties attached to the element, you could do something like this:

 foreach(var item in element)
 {
     foreach(var property in item.GetType().GetProperties())
     {
          // property.Name = Name of property.
          // property.GetValue(element, null) - Gets the value of the property (as System,Object).
     }
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消