We at Appsolo Ltd have been building a non-standard Business application in RIA Services. I just though I would share some things that have arisen during the latter stage of development.
The procedure for setting up an Entity Domain Model (.edmx)
has been well documented here on the appsolo blog and elsewhere, as has been the argument of using Views on the database or DTO on the web server for joins.
For Joins where you want all the fields from the two tables or for a small number of records of small spans there is also the technique of using the Include statement which is part of Linq to EF in the Domain Service Class
and not forgetting to put in the tag in the Metadata part of the Domain Services class
1: public IQueryable<Node> GetNodesByID(int n)
2: {
3: IQueryable<Node> NodesByMaster;
4: NodesByMaster = this.ObjectContext.Nodes.Include("Arc").Where(node => node.NodeID == n);
5: return NodesByMaster;
6: }
1: [MetadataTypeAttribute(typeof(Node.NodeMetadata))]
2: public partial class Node
3: {
14: internal sealed class NodeMetadata
15: {
16:
18: private NodeMetadata()
19: {
20: }
21:
22: [Include]
23: public Arc Arc { get; set; }
24:
25: public int ArcID { get; set; }
26:
27: public Nullable<bool> IsRoot { get; set; }
28:
29: public int NodeID { get; set; }
30:
31: public NodeMaster NodeMaster { get; set; }
32:
33: public Nullable<bool> Terminal { get; set; }
34: }
35: }
Linq to SQL does not work too well in the domain class being probably better suited to being used in the Entity Data Model Designer.cs code as the Entity objects that are returned from the EDM do not translate too easily into IQueryables.
A further annoyance is that it is not well documented, is the importance of the Allow Edits box is checked when you are using the Wizard to set up the Domain service class. This is of particular importance if you have to change the Data Model in the Database regularly as you invariably have to with application development in the early stage of flux. If you do not delete and recreate the domain data source and just update the the EDM by right clicking on it then you do not get Entity objects that are Editable. Surely Editable should be the default. Especially as you can change the behaviour on the client or front domain service side. The code that dictates which entities are editable (produced by the Wizard) is buried in some .g.cs files and not immediately available. Well not to me anyway. If someone knows were it is can they post a comment please. This leads to unpredictable behaviour on the Silverlight client side as it does not throw an error or even a warning on binding, works on reads, but crashes the Browser when trying to do an edit through a domain data source linked via a domain service query and Entity Objects to tables in the database.
So the procedure if you make changes in the database is to drop the domain service and the EDM and set them up again. But if you do this then you will loose any customised queries that you have written in the Domain service class and indeed any metadata attributes you may have added in the Domain.metadata.cs a partial solution we have applied at Appsolo is to use a partial class of the domain service class
TaxFullDbDom.cs
1: public partial class TaxFullDbDom : LinqToEntitiesDomainService<db1084688_TaxonomyEntities>
2: {
3:
4: // TODO:
5: // Consider constraining the results of your query method. If you need additional input you can
6: // add parameters to this method or create additional query methods with different names.
7: // To support paging you will need to add ordering to the 'Arcs' query.
8: public IQueryable<Arc> GetArcs()
9: {
10: return this.ObjectContext.Arcs;
11: }
12:
TaxDomExtra.cs
1: public partial class TaxFullDbDom : LinqToEntitiesDomainService<db1084688_TaxonomyEntities>
2: {
3: //[Query]
4: // Also changed return type from IQueryable<Arc>
5: public Arc GetArcsByID(int aID)
6: {
7: return this.ObjectContext.Arcs.SingleOrDefault(a => a.ArcID == aID);
8: }
At last a sensible
Now while this will solve the problem of the deletion and re-creation of the Domain Service Class and the EDM it will not protect the Meta-Data attribute information. So lets be careful out there.
RIA could be a very productive framework to do the donkey work for Silverlight and others and yes it is only out since 2009 and is only now officially in Version 1.0 having spent some time in Beta and RC and the after all the alternative is writing loads WCF data contract code. So it’s probably still worth the time if you can come to grips with the complexity of the RIA framework. We’ve spent a lot of time trying to figure out the intricacies of a poorly but improving documented RIA services. That’s all the time I have. Comments?
P.
