Learn about Entity Framework Other query methods Sql,raw SQL Analysis

Source: Internet
Author: User

One: LINQ is not a unique query for EF ...

Two: Entity Sql

1. ESQL = Entity SQL ... "Class SQL language" is about the same as SQL, but not SQL ...

using (schooldbentities db = new Schooldbentities ())
{
Querying with Object Services and Entity SQL
String sqlString = "Select Value s from schooldbentities.students as S"; SELECT * FROM Student

var objctx = (db as Iobjectcontextadapter). ObjectContext;

Objectquery<student> Student = objctx. Createquery<student> (sqlString);

var query = student. ToList ();
}

Learn about a grammar ...


Official website: https://msdn.microsoft.com/zh-cn/library/bb399560.aspx


2. Entityconnection,entitycommand ....


Use the soundtrack for a little bit of command


using (var con = new EntityConnection ("Name=schooldbentities"))


The "Name=schooldbentities" here is the database connection string that gets the Schooldbentities node in the AppConfig

using (var con = new EntityConnection ("Name=schooldbentities"))
{
Con. Open ();
EntityCommand cmd = con. CreateCommand ();
Cmd.commandtext = "Select VALUE St from schooldbentities.students as St where St." Studentname= ' Nihao ' ";
Dictionary<int, string> dict = new Dictionary<int, string> ();
using (entitydatareader rdr = cmd. ExecuteReader (CommandBehavior.SequentialAccess | CommandBehavior.CloseConnection))
{
while (RDR. Read ())
{
int a = RDR. GetInt32 (0);
var B = rdr. GetString (1);
Dict. Add (A, b);
}
}
}

Rsql + raw sql ... "pour directly into SQL into DB"


People choose according to their hobbies ...


3. Rsql:

"1" repository in the Rsql query ....

Curd operation ...

1. R:var query = db. Students.sqlquery ("SELECT * from Student"). ToList ();


"2" at database level


1. R:var query = db. Database.sqlquery<student> ("SELECT * from Student"). ToList ();


2. c,u,d var query = db. Database.executesqlcommand ("Update Student set studentname= ' Jack2 ' where studentname= ' Jack '");


LINQ is too complex to write well ... Even with the linqer,linqpad ... LINQ <=> SQL

Learn about Entity Framework Other query methods Sql,raw SQL Analysis

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.