2011-06-30 74 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

在類中實現構造函數。內部沒有命名空間