This is a migrated thread and some comments may be shown as answers.

RadEntityFrameworkDataSource returns no rows

3 Answers 77 Views
EntityFrameworkDataSource
This is a migrated thread and some comments may be shown as answers.
Winfried
Top achievements
Rank 1
Winfried asked on 25 May 2015, 02:31 PM

Hello,

 i got an application where the RadEntityFrameworkDataSource returns no rows.

I have written an Test application, which just handles the issue: the problem remains.

You can download the application at http://w2ww.de/downloads/RadEntityFrameworkDataSource_Test1.zip

You must edit the connection string in the app.config.

I used the .Net Framework in the version 4.5 and Telerik Devcraft for WPF in the version 2015.1.0401.45.

 The source:

namespace RadEntityFrameworkDataSource_Test1 {
    class Program {
        [STAThread]
        static void Main(string[] args) {
            REFDS_T1Context cntxt = new REFDS_T1Context();
            cntxt.Database.CreateIfNotExists();
            if (cntxt.Libraries.FirstOrDefault<Library>() == null) {
                Library l = new Library("Lib1");
                cntxt.Libraries.Add(l);
                l = new Library("Lib2");
                cntxt.Libraries.Add(l);
                cntxt.SaveChanges();
            }
            var q = (from m in cntxt.Libraries select m).ToList();
            Console.WriteLine("---- Output from Linq Queryable");
            foreach (Library m in q) {
                Console.WriteLine(m.Name);
            }
            RadEntityFrameworkDataSource refds = new RadEntityFrameworkDataSource();
            refds.DbContext = cntxt;
            refds.QueryName = "Libraries";
            var l2 = refds.DataView;
            Console.WriteLine("Output from RadEntityFrameworkDataSource");
            var v = l2.TotalItemCount;
            Console.WriteLine("TotalItemCount: " + v);
            foreach (Library m in l2) { //.ToEnumerable<MediaItem>()
                Console.WriteLine(m.Name);
            }
            Console.WriteLine("---- Ende for Output of: RadEntityFrameworkDataSource");
            Console.ReadLine();
        }
    }
}

----------- The output:

---- Output from Linq Queryable
Lib2
Lib1
Output from RadEntityFrameworkDataSource
TotalItemCount: 0
---- Ende for Output of: RadEntityFrameworkDataSource

---

Best Regards

    Winfried Wille

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 27 May 2015, 07:42 AM
Hi Winfred,

I modified the connection string as suggested and as it turned out, I was not able to load any data as there is not a table Libraries in my database. 
Would you please try invoking: 
refds.Load();

Does this load the results?

Regards,
Dimitrina
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Winfried
Top achievements
Rank 1
answered on 27 May 2015, 11:23 AM

Hello,

 Load does not fix the problem. There are still no records returned.

That the database is empty is ok. The program inserts at the begin two rows.

Code is below.

 

Regards

Winfried Wille

 

 class Program {
        [STAThread]
        static void Main(string[] args) {
            REFDS_T1Context cntxt = new REFDS_T1Context();
            cntxt.Database.CreateIfNotExists();
            if (cntxt.Libraries.FirstOrDefault<Library>() == null) {
                Library l = new Library("Lib1");
                cntxt.Libraries.Add(l);
                l = new Library("Lib2");
                cntxt.Libraries.Add(l);
                cntxt.SaveChanges();
            }
            var q = (from m in cntxt.Libraries select m).ToList();
            Console.WriteLine("---- Output from Linq Queryable");
            foreach (Library m in q) {
                Console.WriteLine(m.Name);
            }
            RadEntityFrameworkDataSource refds = new RadEntityFrameworkDataSource();
            refds.Load();
            refds.DbContext = cntxt;
            refds.QueryName = "Libraries";
            var l2 = refds.DataView;
            Console.WriteLine("Output from RadEntityFrameworkDataSource");
            var v = l2.TotalItemCount;
            Console.WriteLine("TotalItemCount: " + v);
            foreach (Library m in l2) { //.ToEnumerable<MediaItem>()
                Console.WriteLine(m.Name);
            }
            Console.WriteLine("---- Ende for Output of: RadEntityFrameworkDataSource");
            Console.ReadLine();
        }
    }

0
Winfried
Top achievements
Rank 1
answered on 27 May 2015, 11:36 AM

Hello,

 

in the previous sample, i called load to early. I fixed this, but still no rows are returned.

Regards

    Winfried Wille

refds.DbContext = cntxt;
            refds.QueryName = "Libraries";
            refds.Load();

Tags
EntityFrameworkDataSource
Asked by
Winfried
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Winfried
Top achievements
Rank 1
Share this question
or