I developed WPF / XAML applications that invoke objects (functions or Web services) which retrieve data from various sources (SQL Server DB, Active Directory, Oracle DB, SAP RFC, XML files, flat files, etc.).
These objects always return Datasets, which then bind to datagrids for displaying information to the user, additionally I do interesting things with datasets (join tables, retrieve the metadata/structure, create new columns, etc).
Because WPF is for the desktop, it's getting tedious and expensive to deploy the application in every computer, so I am urged to use "Silverlight Business Application" in order to access the applications via Web and, in the near future, to easily adapt to Windows Phone 7.
It seemed to be easy to move from WPF to Silverlight but I got run into some problems and the main has been at the level of data management: Silverlight does not support Datasets.
I felt a little frustrated because I feel forced to make a copy of all my functions / web services and modify them to return objects 开发者_StackOverflowthat are different from datasets.
However, so far I cannot find an object equal to or better than a dataset which, incidentally, can also let me use it interchangeably in both Silverlight and WPF.
Did anybody find a powerful and convenient solution that surpass the offered by a dataset? If yes, please let me know with examples or links in order to learn.
Thanks!!
If your end users are all using Windows and are on the same network then you will be much better off sticking with WPF and using ClickOnce. I happen to love both WPF and Silverlight but Silverlight is a big freakin wuss when it comes to things people take for granted like file associations, multiple windows, integrating with other applications, etc.
But to answer your question, you will likely need to re-architect your data access strategy and use something like LINQ and WCF Data Services. The tooling support in Visual Studio will let you generate classes that are modeled after your database schema and your Silverlight/WPF UI can bind to these classes directly.
There is this project on CodePlex that seems to have a minimal implementation of DataSet/DataTable but honestly I wouldn't suggest sticking with DataSet. The reason Silverlight doesn't support DataSet is because the people have spoken and developers have rejected the wizard-driven DataSet model in favor of a much cleaner and more flexible ORM (Object-Relational Mapping) technology such as nHibernate or LINQ.
I have not had a whole lot of experience with Silverlight, but for WPF I have been very successful using Entity Framework (version 4, the EF that shipped with .NET 3.5 is kind of so-so).
Once you have defined classes and mapped them to your database tables, you can do all kinds of things that would take forever with datasets.
For instance: data validation. In Entity Framework, entity classes are partial classes, and thus you can customize them to a great degree. I put my validation code in there using a couple of dictionaries that track invalid property values. A little iDataErrorInfo here and there, and voila, I have easily bindable data validation that can trigger style changes in the UI.
I have not yet tried NHibernate or any other ORM tools. One day I will, but for now I have found EF to be enough for my purposes. Easy to figure out, easy to implement, a lot of customization, can be used with LINQ (LINQ to Entities), and it works pretty darned well with WPF.
精彩评论