繁体   English   中英

WCF RIA服务,域服务中的联接表

[英]WCF RIA Services, Joining Tables in Domain Service

我正在制作Silverlight WCF RIA服务应用程序。 虽然,我一直坚持尝试不同的方法来使用数据库中的多个表。 当前,我正在尝试联接域服务类中的表,并将其返回给服务代理。 我从位于以下位置的模板开始了该项目: http : //simplemvvmtoolkit.codeplex.com/wikipage?title=WCF%20RIA%20Services

我正在尝试加入表,如:

    public IQueryable<Invoice> GetInvoices()
    {
        return (from i in this.ObjectContext.Invoices 
                join o in this.ObjectContext.otherTable equals condition 
                join s in this.ObjectContext.otherTable equals condition 
                select i); 
    }

这将根据给定条件正确地连接表。 但是我实际上需要从i.Invoices Tables和s.otherTable中投影项目字段。 有什么建议可以使此投影在DomainServiceClass.cs中起作用?

用户“ Chris”的示例代码建议:

    public class Invoice_PM
    {
    [Key]
    public int InvoiceId { get; set; }

    public string PaymentNum { get; set; }

    public DateTime? PaymentExpDate { get; set; }

    public DateTime? InvoiceDateTime { get; set; }

    [Include, Association("name", "InvoiceID", "InvoiceDateTime")]
    public IEnumerable<InvoiceSoldToShipTo_PM> SoldToShipTo { get; set; }
}

您的LINQ查询仅使用联接来基本过滤发票,因为您在最后选择了i变量。 我认为这篇文章的答案将为您提供所需的结果:

错误:无法在LINQ to Entities查询中构造实体或复杂类型

建议您使用要加载的所有属性创建一个自定义类,然后将LINQ语句的结果选择到自定义类中。

自订类别:

public class CustomInvoice
{
    public int InvoiceID { get; set; }
    public int InvoiceNumber { get; set; }
    public int ProductID { get; set; }
    public string ProductName { get; set; }
    public int InvoiceID { get; set; }
    public string CustomerName { get; set; }
}

域服务功能:

public IQueryable<CustomInvoice> GetInvoices() 
{ 
    return (from i in this.ObjectContext.Invoices  
            join p in this.ObjectContext.Product equals condition  
            join c in this.ObjectContext.Customer equals condition  
            select new CustomInvoice
            { 
                InvoiceID = i.ID, 
                InvoideNumber = i.InvoiceNumber, 
                ProductID = p.ID, 
                ProductName = p.Name, 
                CustomerID = c.ID, 
                CustomerName = c.Name
            }; );  
} 

我没有尝试测试此代码,但是这个想法应该可以帮助您。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM