1) business logic layer: dynamicdatabusi. CS
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. Data;
Using mentities;
Using system. Data. sqlclient;
Namespace bBusiness
{
Public class dynamicdatabusi
{
Public dynamicdatatable getdynamicdatatable (string strsql, string connstr)
{
Sqlconnection theconn = new sqlconnection (connstr );
Datatable thetable = new hdatabase. dynamicdataaccess (). getdatatable (strsql, theconn );
Dynamicdatatable thedynamictable = new dynamicdatatable ();
If (thetable! = NULL)
{
Foreach (datacolumn Col in thetable. columns)
{
Dynamicdatacolumn thecol = new dynamicdatacolumn ();
Thecol. Caption = col. Caption;
Thecol. datatype = col. datatype. Name;
Thecol. fieldname = col. columnname;
Thecol. Length = col. maxlength;
Thecol. formatstring = "";
Thedynamictable. Columns. Add (thecol );
}
Foreach (datarow row in thetable. Rows)
{
Dynamicdatarow therow = new dynamicdatarow ();
For (INT I = 0; I <thetable. Columns. Count; I ++)
{
Dynamicdatafield thedatafield = new dynamicdatafield ();
Thedatafield. fieldname = thetable. Columns [I]. columnname;
Thedatafield. datatype = thetable. Columns [I]. datatype. Name;
Thedatafield. value = row [I];
Therow. datafields. Add (thedatafield );
}
Thedynamictable. Rows. Add (therow );
}
}
Return thedynamictable;
}
}
}
All packages to be provided to the client, as well as server-side real-body caches, can be encapsulated into this layer. Another major function of the business logic layer is the processing of business logic. Simple addition, modification, deletion, and query can be encapsulated here. Some of them are simple calls to the data access layer, but do not allow the service layer to directly call it. This layer provides many functions, such as conflict detection and logic check.
2) RIA service layer: dynamicdataservice
Namespace riaservices. Web
{
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. componentmodel. dataannotations;
Using system. LINQ;
Using system. servicemodel. domainservices. Hosting;
Using system. servicemodel. domainservices. server;
Using mentities;
Using bBusiness;
// Todo: Create a method that contains the application logic.
[Enableclientaccess ()]
Public class dynamicdataservice: domainservice
{
Static string conn = "Data Source = 127.0.0.1; initial catalog = devtest; persist Security info = true; user id = sa; Password = tian777888 ";
[Invoke]
Public dynamicdatatable getdynamictable (string strsql)
{
// Check whether the call is legal
Return new dynamicdatabusi (). getdynamicdatatable (strsql, Conn );
}
}
}
It is a coincidence that my database connection appears at this layer. The database connection should be stored in the data access layer or configuration file. If it is a complicated application, such as SaaS, separate classes are also required for management.
In addition, I did not directly place the service layer on the webapp that hosts the Silverlight client, but instead set up the RIA service library.
Here, the implementation of the server is complete. After compilation, the client can see our entities and call the service method.
Later, we will continue to build the client application.
Friendly reminder: After the above Code is tested, it is absolutely OK. Note that your WCF Ria services must at least be SP1; otherwise, a compilation error occurs.