How to prepare data for display on a silverlight chart using WCF RIA Services + Entity Framework

I used the WCF RIA services with the Entity Framework to create a simple application that can display and update school course data. This was done following Microsoft's instructions. Now, I would like to have a chart that shows how many courses are at a key stage.

Example:

Key stage 3 - 20 courses
Key stage 4 - 32 courses
Key stage 5 - 12 courses

Displayed in any form of chart. I have no problem binding data to a chart in XAML. My problem is that I do not know how to fix the way to get data in this format. Created CRUD methods are basic.

I have a few thoughts on possible ways, but I don’t know what is right, they are:

  • Create a view on the SQL server and map it to a single object in the entity data model. Creating new CRUD methods for this is automatic.

  • Set up a read method in an existing DomainService using .Select (). Distinct (), etc. I don’t know that this syntax is very good for the crib expression / LINQ ??? what is it? Any good quick starts on it?

  • Create a new class to store only the necessary data and create a reading method for it. I tried this, but did not know how to make it work without the corresponding object in the entity model.

  • Something I don't know about.

, , , , . , .

+3
3

- . , , . , 10 , 2. .

, ,

:

public class Kitteh
{
    public string Name { get; set; }  
    public int Age { get; set; }
}

Entity Query:

public Iqueryable<Kitteh> getKittehz
{
    var result = from x in Data.TblCats
                 select new Kitteh  
                 {
                    Name = x.Name, 
                    Age = x.Age
                 }
    return result;
}

silverlight, MVVM.

http://www.silverlight.net/learn/videos/silverlight-4-videos/mvvm-introduction/

http://www.silverlight.net/learn/tutorials/silverlight-4/using-the-mvvm-pattern-in-silverlight-applications/

+2

.

, , , , .

silverlight chartItem: 2 : Key Value.

... , Dictionary<string,string> myCollection... ObservableCollection<ChartItem> myCollection

- ForEach .

myCollection.Add(new chartItem{ Key= "Key Stage 3", Value = "20 Courses" });
myCollection.Add(new chartItem{ Key= "Key Stage 4", Value = "60 Courses" });
myCollection.Add(new chartItem{ Key= "Key Stage 5", Value = "10 Courses" });

... ,

+1

Entity Framework, / "" (PrimaryKey), , EDMX, ..

,

  • , ChartItems
  • LinqToSQL ViewDB
  • ViewDB
  • ChartItem [] GetChartItems RIA,
public ChartItem[] GetChartItems(..parameters...){
   ViewDB db = new ViewDB();
   return db.ChartItems.Where(...query mapping...).ToArray();
}

The RIA Domain Service Class can contain any arbitrary method that you can directly call the client with parameters. It is as simple as calling a web service. And you have to return the array, because IQueryable may or may not work in some cases, but we prefer Array. You can try IQueryable, but it may not work correctly with linq in SQL.

+1
source

Source: https://habr.com/ru/post/1744511/


All Articles