EF6
http://www.entityframeworktutorial.net/entityframework6/introduction.aspx
EF5
http://www.entityframeworktutorial.net/EntityFramework5/entity-framework5-introduction.aspx
EF Version History and Features links
https://msdn.microsoft.com/en-us/data/jj574253.aspx
EF querying approaches:
## LINQ to Entities:
context.Students.where(s => s.StudentName == “Bill”)
## Entity SQL:
string sqlString = “SELECT VALUE st FROM SchoolDBEntities.Students ” +
“AS st WHERE st.StudentName == ‘Bill'”;
var objctx = (ctx as IObjectContextAdapter).ObjectContext;
ObjectQuery<Student> student = objctx.CreateQuery<Student>(sqlString);
## EntityConnection and EntityCommand:
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=’Bill'”;
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);
}
}
}
## Native SQL:
using (var ctx = new SchoolDBEntities())
{
var studentName = ctx.Students.SqlQuery(“Select studentid, studentname, standardId from Student where studentname=’Bill'”).FirstOrDefault<Student>();
}
OR
// extract only a string INSTEAD of a full entity.
var studentName = ctx.Database.SqlQuery<string>(“Select studentName from Students where ID=1”).FirstOrDefault<string>();
LINQ Reference