使用 MVC2 向构造函数添加多个参数

发布于 2024-11-18 00:28:10 字数 840 浏览 1 评论 0原文

我有以下 LINQ 查询,它从数据库返回两个对象。这些对象将由强类型化为显示模板的 ViewModel 使用:

 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)
    {
    }
}

我收到语法错误,指出不能在 for、using 或fixed 声明中使用多种类型。
我做错了什么?

I have the following LINQ query that returns two objects from my database. These objects will be consumed by a ViewModel that is strongly typed to a display template:

 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);
     }
}

I am trying to create a new CustomersAndSitesMix class with a constructor that accepts two parameters (the customer and the site).

However, when I create the class and try to set up the constructor like so:

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

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

I get syntax errors stating that cannot use more than one type in a for, using or fixed declaration.
What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝眸 2024-11-25 00:28:10

您应该首先声明该类:

// 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)
        {
        }
    }
}

You should declare the class first:

// 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)
        {
        }
    }
}
祁梦 2024-11-25 00:28:10

在类内部实现构造函数。不在命名空间内

Implement constructor inside class. Not inside namespace

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文