Do your own ormapping Framework----Sixth talk about starting Ormapping tour, ormapping how to say

Source: Internet
Author: User

These days the company has a little thing, not how to come this way, now here to introduce the next ormapping realize something

Speaking of ormapping, of course, is the database of the additions and deletions to change, the class diagram here I simply got the next

The following code is I in the framework of the source, the editor is very poor, paste it will be a bit ugly, the interface of the method properties are often used in my development, what the basic look at the name to know, here also have to say, code is really important, children write code when more attention points.

  

Public Interface Ientityaccesser
{
bool Exist<t> (T obj), presence monitoring
void insert<t> (T obj);
void update<t> (T obj);
void delete<t> (T obj);
bool Load<t> (T obj) where t:ientity; loading data from a database
list<t> search<t> (String condition = "", String order = "") where t:ientity, new (); Check
list<tentity> Search<towner, tentity> (towner owner, Expression<func<towner, IEnumerable> > Exp, string order = "") where tentity:ientity, new ();
int ExecuteCommand (string cmdtext); Execute SQL command

void Executestoreprocedure (String procedurename, ienumerable<spparameter> args); Executing stored procedures
Object Executestoreprocedurescalar (String procname, ienumerable<spparameter> args); Execute stored procedure and get return value
}

Public Interface Iormapper:ientityaccesser
{
string and {get;}
string Comma {get;}
string Conditionsql {get;}
string Countsql {get;}
string Deletesql {get;}
string Dot {get;}
string Equal {get;}
string Findattributesql {get;}
string Findsql {get;}
string Insertsql {get;}
string Join {get;}
string Keysqlvalueparameter {get;}
string Keysqlvalueparametername {get;}
string on {get;}
string Ordersql {get;}
string semicolon {get;}
string SetSQL {get;}
string Updatesql {get;}
string Updatesqlvalueparameter {get;}
string Updatesqlvalueparametername {get;}
string Wheresql {get;}
string Leftsquare {get;}
string Rightsquare {get;}
string Storeprocedureexistsql {get;}
string Createdatabasesql {get;}
string Dropdatabasesql {get;}
string commandspitterregexstring {get;}
string Databaseexistsql {get;}
string Masterdatabasename {get;}

IDbConnection newconnection ();

IDbConnection getdatabaseconnection (string databaseName);

void CreateDatabase (string databaseName);
void Executesqlresourcefile (Type typeinresourceassembly, String filequalifiedname, idbconnection connection, BOOL Splitcommands);
void Dropdatabase (string databaseName);
bool Databaseexist (string databaseName);
bool Storeprocedureexist (string databaseName, String storeproceudrename);
string GetDatabaseName ();
string Getdatabasehost ();
bool Issystemdatabase (string databaseName);
void waituntilconnectionbeused (idbconnection connection, int retrytimes =, int retryInterval = $);

  BOOL Executetruefalseresultsqlquery (string sqlstatement);

}

public interface Ibatchormapper:iormapper
{
string Getupdatesetitem (String columnName, int parameterindex);
string getparametername (int index);

BOOL Exist<t> (string condition, params object[] parametervalues);
void Update<t> (String setsql, string condition, params object[] parametervalues);
void delete<t> (string condition, params object[] parametervalues);
List<t> search<t> (string condition, params object[] parametervalues) where t:new ();
}

The next step is to really start the implementation of our Ormapping class.

Public abstract class Ormapper:ibatchormapper
{

}

[Export (typeof (Iormapper)]) here using MEF for different data ormapping expansion, I am here in SQL Server for example, the others are the same
[ExportMetaData ("Entityaccessertype", Entityaccessertype.sqlserver)]
public class Sqlserverormapper:ormapper
{

}

public class Entityaccesserfactory This side is the management and use of ormapping
{
public static Ientityaccesser Getentityaccesser (Entityaccessertype accessertype, String connectionString)
{
Switch (accessertype)
{
Case Entityaccessertype.sqlserver: Other database types are similar
return new Sqlserverormapper (connectionString);
Default
throw new NotSupportedException ();
}
}
}

This code structure you should be easy to understand, there is no complicated structure, do not understand the MEF friends can consult the relevant information, here is not much to say, today introduced here, the next chapter will introduce the library table information acquisition and how to automatically generate your SQL command

Thank you.

Do your own ormapping Framework----Sixth talk about starting Ormapping tour, ormapping how to say

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.