Mapper Automap:
Mapper.CreateMap<ObjectType1, ObjectType2>()
.ForMember(o1 => o1.PropName, mapper => mapper.MapFrom(o2 => o2.Prop2Name));
Mapper.Map(object1, object2);
Run Code Online (Sandbox Code Playgroud)
隐含运算符:
public static implicit operator Object1(Object2 o2)
{
Object1 o1 = new Object2();
//Mapping code here...
return o1;
}
Run Code Online (Sandbox Code Playgroud) 我在我的数据访问层使用Entity Framework 5,ObjectContext和POCO.我有一个通用的存储库实现,我有一个方法,使用Skip()和Take()通过分页查询数据库.一切正常,但跳过很多行时查询性能非常慢(我说的是170k行)
这是我对Linq to Entities的查询的摘录:
C#代码:
ObjectContext oc = TheOBJEntitiesFactory.CreateOBJEntitiesContext(connection);
var idPred = oc.CreateObjectSet<view_Trans>("view_Trans").AsQueryable();
idPred = idPred.OrderBy(sortColumn, sortDirection.ToLower().Equals("desc"));
var result = idPred.Skip(iDisplayStart).Take(iDisplayLength);
return new PagedResult<view_Trans>(result, totalRecords);
Run Code Online (Sandbox Code Playgroud)
在翻译的查询到的Transact-SQL我注意到,而不是使用ROW_NUMBER()直接条款与鉴于其作出一个子查询和应用ROW_NUMBER()的子查询的结果...
例:
select top(10) extent1.A, extent1.B.extent1.C from (
select extent1.A, extent1.B, extent1.C,
row_number() OVER (ORDER BY [Extent1].[A] DESC) AS [row_number]
from (
select A,B,C from table as extent1)) as extent1
WHERE [Extent1].[row_number] > 176610
ORDER BY [Extent1].[A] DESC
Run Code Online (Sandbox Code Playgroud)
这需要大约165秒才能完成.有关如何提高翻译查询语句性能的任何想法?