I have some trouble understanding what you mean, so I will rephrase your questions the way I understand them.
Q: How can I convert IQueryable<T> to DataTable?
A: This is highly ineffective and inadvisable, because there is no way to accomplish this without executing the query. If this is what you want to do, here is a sample implementation from StackOverflow
IQueryable value, DataTable table)
var reader = value.GetEnumerator();
var record = (Customer)reader.Current;
This is an extension method
, and, of course, you should replace Customer and its fields with Document and document fields.
Again, I would strongly advice you against converting to DataTable unless you have to work with some legacy code.
Q: Is there a way to get all fields in a database row?
A: Sure there is
, but you have to implement it yourself with either standard ADO.NET or some other technology. Sitefinity chose to use ORM
software, and we settled on OpenAccess
. As such, we use classes that are mapped to rows, and class fields are mapped to table columns. Since C# is a compiled
language, we have only a part of the table's definition abailable directly through languace constructs. The rest is available through reflection, or what is called introspection in some other languages. We provide convenient wrappers (e.g. .GetValue
extension methods) that allow you to modify those fields that are not directly available as properties.
Summary: you get your rows as classes (commonly called Models in Sitefinity), which contain all the information that is mapped through the ORM. Statically available are only the fields that are declared in the class. The rest is available through the utility methods GetValue and SetValue. The objects themselves are retrived via manager methods (e.g. GetDocuments()).
One quick way to retrieve all mapped fields of an object is: TypeDescriptor.GetProperties(document)
and then use PropertyDescriptor.GetValue
to get/set value.
Q: When binding, a Grid displays all columns, not just the class peroperties. How do I retrieve those values programatically?
Data-bound controls in ASP.NET commonly use property descriptors. As I explained in the previous question, Sitefinity provides all values via property descripors. There are convenient wrappers - .GetValue
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Telerik Public Issue Tracking
system and vote to affect the priority of the items