Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 如何提高Linq查询表达式的性能?_Performance_Linq_Nhibernate_Plinqo - Fatal编程技术网

Performance 如何提高Linq查询表达式的性能?

Performance 如何提高Linq查询表达式的性能?,performance,linq,nhibernate,plinqo,Performance,Linq,Nhibernate,Plinqo,,实际上,我通过args方法得到了一个字符串数组,然后我想通过ticketNos从数据库中获取所有数据,这里我使用了一个循环,我知道如果我这样编写代码,将导致性能问题,并导致再次访问数据库,如何避免这个问题并提高代码性能,例如,仅通过数据库访问获取所有数据 我忘了告诉你我使用的ORM,恩,ORM是基于PlinqO的NHibernate Orderticket temp = context.Orderticket.ByTicketNo(ticketNo).SingleOrDefault(); 我

,实际上,我通过args方法得到了一个字符串数组,然后我想通过ticketNos从数据库中获取所有数据,这里我使用了一个循环,我知道如果我这样编写代码,将导致性能问题,并导致再次访问数据库,如何避免这个问题并提高代码性能,例如,仅通过数据库访问获取所有数据 我忘了告诉你我使用的ORM,恩,ORM是基于PlinqO的NHibernate

Orderticket temp = context.Orderticket.ByTicketNo(ticketNo).SingleOrDefault();
我期待着得到您的每一个答案,谢谢您使用纯NHibernate

Orderticket temp = context.Orderticket.ByTicketNo(ticketNo).SingleOrDefault();
var tickets=session.QueryOver()
.WhereRestrictionOn(x=>x.TicketNo).IsIn(ticketNos)
.List();
短?type=null;
短型值;
if(!string.IsNullOrEmpty(checkType)和&short.TryParse(checkType,out-typeValue))
类型=类型值;
var entitiesToSave=tickets.Select(ticket=>newcarstartiket
{
CsltId=Guid.NewGuid().ToString(),
Carstartlist=new Carstartlist(){CslId=id},
LeaveDate=票证。LeaveDate,
OnPointName=ticket.OnPointName,
OffPointName=票证。OffPointName,
OutTicketMan=ticket.OutBy,
TicketNo=ticket.TicketNo,
切克曼=支票员,
CreatedOn=DateTime。现在,
CreatedBy=checkMan,
类型=类型,
NumberAllowance=GetPersonCountAllowance(上下文,ticket.Ticketline,ticket.CurrencyType)
});
foreach(entitiesToSave中的var实体)
{
session.Save(实体);
}

为了进一步增强这一点,请尝试预加载所有需要的人员分配

谢谢您的帮助,您给了我另一个思路
var tickets = session.QueryOver<OrderTicket>()
    .WhereRestrictionOn(x => x.TicketNo).IsIn(ticketNos)
    .List();

short? type = null;
short typeValue;
if (!string.IsNullOrEmpty(checkType) && short.TryParse(checkType, out typeValue))
    type = typeValue;

var entitiesToSave = tickets.Select(ticket => new Carstartlistticket
{
    CsltId = Guid.NewGuid().ToString(),
    Carstartlist = new Carstartlist() { CslId = id },
    LeaveDate = ticket.LeaveDate,
    OnPointName = ticket.OnpointName,
    OffPointName = ticket.OffpointName,
    OutTicketMan = ticket.OutBy,
    TicketNo = ticket.TicketNo,
    ChekMan = checkMan,
    CreatedOn = DateTime.Now,
    CreatedBy = checkMan,
    Type = type,
    NumbserAllowance = GetPersonCountAllowance(context, ticket.Ticketline, ticket.CurrencyType)
});

foreach (var entity in entitiesToSave)
{
    session.Save(entity);
}