[英]ServiceStack and entity framework Lazy Loading
我正在将WCF Web服务迁移到ServiceStack。 假设我们有3个实体。 让它们成为A,B和C。
在WCF中,我们将有3种方法来让A和他的孩子们在一起:
public List<A> GetAWithBIncluded()
{
return Repository.A.Include("B").ToList();
}
public List<A> GetAWithCIncluded()
{
return Repository.A.Include("C").ToList();
}
public List<A> GetAWithBAndCIncluded()
{
return Repository.A.Include("B").Include("C").ToList();
}
我很难将此过程转换为ServiceStack方式。 你们能提供一些例子吗?
我想到的最好的是:
public class AResponse
{
public List<A> As {get;set;}
....//One list of each type.
}
我们知道我们不能将WCF与延迟加载一起使用,但是ServiceStack和ormlite能否在不过度收费应用程序的情况下实现完全自动化的数据访问过程的窍门?
如果您使用的是EF,则可能会执行以下操作:
[Route("/a")]
public class GetAs : IReturn<List<A>>
{
public bool IncludeB { get; set; }
public bool IncludeC { get; set; }
}
public class AService : Service
{
private readonly AContext _aContext;
public AService(AContext aContext)
{
_aContext = aContext;
}
public object Get(GetAs req)
{
var res = _aContext.As;
if (req.IncludeB)
res = res.Include("B");
if (req.IncludeC)
res = res.Include("C");
return res.ToList();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.