Silverlight practice example 4 (and the use of set attributes)-business logic and service layer

Source: Internet
Author: User

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.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.