Using Silverlight + WCF Ria service + ado.net entity or linqtosql provided by Microsoft is indeed very simple and fast for systems with small development and less complex business logic, during these two days of study, I have some small experiences,
However, using existing frameworks (such as nhib.pdf and sprint.net) has never been my style, because I prefer controllability. Although these frameworks are good things, after all: 1. They all serve the world, and if they are too full, they will inevitably be "not refined", and my choice only needs to be responsible for my own system, too many things are useless or too cumbersome for me. 2. Things are good, but after all, they are blocked and need to add some fast development functions suitable for my system, it is not easy.
Over the past few days, I have constructed a simple framework for my own system. I hope you can give me some advice on the initial introduction of yinguang with limited capabilities.
The overall architecture is: database + model layer + UI Layer (view + view model layer) (this is the mvvm mode of Silverlight ).
I mainly focus on the model layer and divide it into the database access layer, data access layer, business logic layer and external service layer, plus a public entity layer.
Database access layer: it mainly deals with databases. It is used as a layer separately to support multiple types of database access. Of course, at this layer, I will provide a unified access interface to the data access layer.
Data access layer: This layer mainly enables access to specific business data, such as obtaining entities. This layer encapsulates access to specific business SQL statements. To avoid the differences between database SQL statements, similarly, a unified interface is provided to the business logic layer for access.
Business logic layer: the control of business logic is mainly here. This layer is unrelated to the database type. Generally, only the entity or able operations are performed.
The previous layers form class libraries using traditional programming methods for other layers to call.
External Service Layer: WFC Ria service is used to provide services to the Silverlight client for calling. In addition to some permission control, this layer basically calls the business logic layer.
Entity layer: The ing between database tables and entity classes.
There may be many layers above. The main reason why the external service layer is not used as the business logic layer is that the external service layer is dedicated to the Silverlight client and other applications cannot be accessed. The advantage of this method is that it can be used at or below the business logic layer, such as winform, web, WebService, and WCF, with great flexibility.
The following is the specific code (classes can be stored in sub-databases, and some layers are too large to be divided into projects ):
Public class dbhelper
{
/// <Summary>
/// Execute the query statement and return Dataset
/// </Summary>
/// <Param name = "sqlstring"> query statement </param>
/// <Returns> dataset </returns>
Public dataset querydata (string sqlstring, dbconnection Conn, dbtransaction trans)
{
Sqlconnection connection = conn as sqlconnection;
Connection. open ();
Try
{
Dataset DS = new dataset ();
Sqldataadapter command = new sqldataadapter (sqlstring, connection );
Command. Fill (DS, "ds ");
Command. Dispose ();
Return Ds;
}
Catch
{
Return NULL;
}
}
}
Public class employee_d
{
/// <Summary>
/// Obtain an object
/// </Summary>
Public list <employee_e> getmodellist (string strwhere, dbconnection Conn, dbtransaction trans)
{
Stringbuilder strsql = new stringbuilder ();
Strsql. append ("select * From employeeinfo ");
Strsql. append ("where 1 = 1 ");
Strsql. append (strwhere );
List <employee_e> thelists = new list <employee_e> ();
Dataset DS = new dbhelper (). querydata (strsql. tostring (), Conn, trans );
If (Ds! = NULL & Ds. Tables. Count> 0)
{
Foreach (datarow row in DS. Tables [0]. Rows)
{
Employee_e themodel = new employee_e ();
Themodel. employeeid = int. parse (row ["employeeid"]. tostring ());
Themodel. employeeage = int. parse (row ["employeeage"]. tostring ());
Themodel. employeedesc = row ["employeedesc"]. tostring ();
Themodel. employeename = row ["employeename"]. tostring ();
Themodel. dicts. Add ("Sss", 100 );
Thelists. Add (themodel );
}
}
Return thelists;
}
}
Public class employee_ B
{
/// <Summary>
/// Obtain an object
/// </Summary>
Public list <employee_e> getmodellist (string strwhere, string connstr)
{
Sqlconnection theconn = new sqlconnection (connstr );
Return new employee_d (). getmodellist (strwhere, theconn, null );
}
}
// Todo: Create Methods containing your application logic.
[Enableclientaccess ()]
Public class mycommonbusi: domainservice
{
Static string conn = "Data Source = 127.0.0.1; initial catalog = devtest; persist Security info = true; user id = sa; Password = tian777888 ";
Public list <employee_e> getentitys ()
{
Return new employee_ B (). getmodellist ("", Conn );
}
[Invoke]
Public String updateemployee (employee_e Model)
{
Return Model. keyValue + "is updated! ";
}
[Invoke]
Public int gettemp (employee_e model, string AAA)
{
Return 100;
}
}
Public interface ientitibase
{
[Datamember]
Dictionary <string, int> dicts {Get ;}
[Datamember]
[Key]
String keyValue
{
Get;
}
}
[Datacontractattribute (isreference = true)]
Public class employee_e: ientitibase
{
// Metadata classes are not meant to be instantiated.
[Datamember]
Public nullable <int> employeeage {Get; set ;}
[Datamember]
Public String employeedesc {Get; set ;}
[Datamember]
[Key]
Public int employeeid {Get; set ;}
[Datamember]
Public String employeename {Get; set ;}
[Datamember]
Public int SSS
{
Get
{
Return dicts ["Sss"];
}
}
[Datamember]
Private dictionary <string, int> _ dicts = new dictionary <string, int> ();
Public dictionary <string, int> dicts
{
Get {return _ dicts ;}
}
Public String keyValue
{
Get {return employeeid. tostring ();}
}
}