2011-06-30 76 views
0

我有以下LINQ查询从我的数据库返回两个对象。这些对象将由ViewModel是强类型的显示模板消耗:使用MVC2向构造函数添加多个参数

public IQueryable<ICustomerSiteRepository> CustomerAndSites 
{ 
    get 
    { 
     return from customer in customerTable 
        join site in customerSitesTable 
         on customer.Id equals site.CustomerId 
       select new CustomersAndSitesMix(customer, site); 
    } 
} 

我想创建一个新的CustomersAndSitesMix类接受两个参数(客户和网站)的构造函数。

然而,当我创建类,并尝试建立构造像这样:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace CustomerDatabase.Domain.Entities 
{ 
    public class CustomersAndSitesMix (CustomerSite custSite, Customer cust) 
    { 
    } 
} 

我得到的语法错误,指出不能在使用一个以上的类型,使用或固定的声明。
我在做什么错?

回答

3

你应该声明类第一:对我而言

// This is the namespace 
namespace CustomerDatabase.Domain.Entities 
{ 
    // This is the class declration 
    public class CustomersAndSitesMix 
    { 
     // this is the constructor 
     public CustomersAndSitesMix(CustomerSite custSite, Customer cust) 
     { 
     } 
    } 
} 
+0

谢谢你们的快速反应,学校的男孩错误。 – Liam

+0

谢谢,我需要为这个方法中的对象添加单独的属性吗?即时通讯思维不像他们在我的实体,最终我想创建一个列表包含两个对象的属性? – Liam

+0

@Liam,你不应该在构造函数中添加属性。属性被添加到类中。 –

1

在类中实现构造函数。内部没有命名空间