1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Get DynamicData value from Document

Get DynamicData value from Document

6 posts, 2 answered
  1. RAFIQ
    RAFIQ avatar
    4 posts
    Registered:
    22 Dec 2010
    20 Jan 2011
    Link to this post
    How do i get Dynamic Data value from database.
    For e.g
    When i create module i created Dynamic Column using SetValue ("Column1", "valueofcolumn1")
    at the same time i want to retrieve that  Column1 value i.e valueofcolumn1 using  

    IQueryable<Document> & 

    App.WorkWith()
                          .Documents()
                          .Where(item => item.Column1)
                         .get()

    or some other method is there to retrieve data?

    Is it possible to Convert IQueryable<Document> to DataTable?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    20 Jan 2011
    Link to this post
    Hello RAFIQ,

    You can use Telerik.Sitefinity.Model.DataExtensions.GetValue

    model.GetValue(dynamicField.FieldName)

    Best wishes,
    Ivan Dimitrov
    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? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. RAFIQ
    RAFIQ avatar
    4 posts
    Registered:
    22 Dec 2010
    20 Jan 2011
    Link to this post
    Is there any way to get all DynamicData Value from particular row? 
    also is it possible to convert IQueryable<Document>  to DataTable?
  4. RAFIQ
    RAFIQ avatar
    4 posts
    Registered:
    22 Dec 2010
    20 Jan 2011
    Link to this post
    Hi,

    IQueryable<Document> GetApplications have some data.when i am bind in Grid and mapping the dynamic data column It is Showing the values from DB.

    i want to get those value in code behind itself with out bind in grid.


  5. Dido
    Dido avatar
    149 posts
    Registered:
    24 Sep 2012
    25 Jan 2011
    Link to this post
    Hi RAFIQ,

    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:
    public static DataTable AsDataTable(this IQueryable value, DataTable table)
    {
        var reader = value.GetEnumerator();
     
        while (reader.MoveNext())
        {
            var record = (Customer)reader.Current;
            table.Rows.Add(record.CustomerID, record.City);
        }
     
        return table;
    }
    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, strongly-typed 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 and .SetValue 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 and PropertyDescriptor.SetValue 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 and .SetValue extension methods.

    Kind regards,
    Dido
    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? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  6. Kevin
    Kevin avatar
    20 posts
    Registered:
    14 Jun 2010
    11 Mar 2011
    Link to this post
    Are you able to do something like 

    App.WorkWith()
                          .Documents()
                          .Where(item => item.Column1 == "someValue")
                         .get()
6 posts, 2 answered