Oledbconnection,oracleconnection or SqlConnection this connection, execute the SQL statement directly. Now the connection way to execute the SQL statement has a very big difference, the following first look at a simple list of additions and deletions to check the operation, and then look at the multiple table of the associated query, with parameter inquiries.
First, ado.net entity to change and check the deletion of Tanku
There is a table, that is, an entity user in the project, and for testing convenience, all fields are string type.
1. Add new records
Add a record as follows:
[CSharp]
using (oracleentities entities = new Oracleentities ())
{
User Uer = user.createuser ("id", "name", "Age", "1");
Entities. User.addobject (user);
Entities. SaveChanges ();
using (oracleentities entities = new Oracleentities ())
{
User Uer = user.createuser ("id", "name", "Age", "1");
Entities. User.addobject (user);
Entities. SaveChanges ();
}
2, delete content
Copy Code code as follows:
using (oracleentities entities = new Oracleentities ())
{
User User = entities. User.first<user> (a => a.id. Equals ("id"));
Entities. DeleteObject (user);
Entities. SaveChanges ();
}
using (oracleentities entities = new Oracleentities ())
{
User User = entities. User.first<user> (a => a.id. Equals ("id"));
Entities. DeleteObject (user);
Entities. SaveChanges ();
}
3, modify the content
Copy Code code as follows:
using (oracleentities entities = new Oracleentities ())
{
User User = entities. User.first<user> (a => a.user.equals ("id"));
User. remarks = "Modified content";
Entities. SaveChanges ();
}
using (oracleentities entities = new Oracleentities ())
{
User User = entities. User.first<user> (a => a.user.equals ("id"));
User. remarks = "Modified content";
Entities. SaveChanges ();
}
4, inquiry content
(1) Entity Direct inquiry
[/code]
using (oracleentities entities = new Oracleentities ())
{
objectquery<user> result = entities. user;//Query All
foreach (User item in result)
{
}
}
using (oracleentities entities = new Oracleentities ())
{
objectquery<user> result = entities. user;//Query All
foreach (User item in result)
{
}
}
[/code]
(2) ESQL query
Copy Code code as follows:
objectquery<dbdatarecord> result = entities. Createquery<dbdatarecord> ("Select value it from Oracleentities.user as it");
(3) Check according to the condition
Copy Code code as follows:
var result = entities. User.where (o => o.id.equals ("id"));
second, related query
For example, there is another table other than the User Foreign Key association.
The query is as follows:
Copy Code code as follows:
using (oracleentities entities = new Oracleentities ())
{
String esql = "Select B.detail from Oracleentities.user as a,oracleentities.other as B where A.otherid = b.ID and a.id= ' id" '";
objectquery<dbdatarecord> query = entities. Createquery<dbdatarecord> (ESQL);
foreach (DbDataRecord r in query)
{
string ss = r["Detail"]. ToString ();
}
}
using (oracleentities entities = new Oracleentities ())
{
String esql = "Select B.detail from Oracleentities.user as a,oracleentities.other as B where A.otherid = b.ID and a.id= ' id" '"; Www.jb51.net
objectquery<dbdatarecord> query = entities. Createquery<dbdatarecord> (ESQL);
foreach (DbDataRecord r in query)
{
string ss = r["Detail"]. ToString ();
}
}
These are, of course, the most basic usage, because the use of LINQ and eSQL is described later in the usage of LINQ and ESQL.