Entity Framework + DbDataReader 方法
using System.Data; public IQueryable<… …> Get…(long id) { List<… …> list = new List<… …>(); string sql = @"SELECT … FROM … "; var connection = this.dao.Context.Database.Connection as System.Data.Common.DbConnection; DbCommand command = this.dao.Context.Database.Connection.CreateCommand(); command.CommandText = sql.ToString().Trim(); connection.Open(); using (DbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { … obj = new …(); … … list.Add(obj); } } return list.AsQueryable(); } |
It is worked for some Complex Query or for some Large Amount of Returned Record(s) ( > 10000 ) with great performance than Entity Framework LINQ.
It is possible to have better performance than ( this.dao.Context.Database.SqlQuery<… …>( sql ) ) <= Not Ensured.
It is possible to have better performance than ( this.dao.Context.Database.SqlQuery<… …>( sql ) ) <= Not Ensured.