Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在单视图mvc中显示多个表_C#_Asp.net Mvc_Viewmodel - Fatal编程技术网

C# 在单视图mvc中显示多个表

C# 在单视图mvc中显示多个表,c#,asp.net-mvc,viewmodel,C#,Asp.net Mvc,Viewmodel,我有两个相互关联的表。我希望能够在单个视图中同时查看信息。但是,当我尝试使用VolumeRates表中的属性时,会出现以下错误: 错误CS1061“ICollection”不包含“BidRate”的定义,并且找不到接受类型为“ICollection”的第一个参数的扩展方法“BidRate”。是否缺少using指令或程序集引用?TimberSales C:\Users\kraskell.CDATRIBE2\Documents\Visual Studio 2017\Projects\TimberSa

我有两个相互关联的表。我希望能够在单个视图中同时查看信息。但是,当我尝试使用VolumeRates表中的属性时,会出现以下错误:

错误CS1061“ICollection”不包含“BidRate”的定义,并且找不到接受类型为“ICollection”的第一个参数的扩展方法“BidRate”。是否缺少using指令或程序集引用?TimberSales C:\Users\kraskell.CDATRIBE2\Documents\Visual Studio 2017\Projects\TimberSales\TimberSales\Controllers\DataEntryController.cs 18处于活动状态

我的模型的代码是

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TimberSales.Models;

namespace TimberSales.Controllers
{
    public class DataEntryController : Controller
    {
        // GET: DataEntry
        public ActionResult Index()
        {
            TimberSalesEntities db = new TimberSalesEntities();
            List<TimberSale> timberSales = db.TimberSales.ToList();

            List<DataEntry> dataEntries = timberSales.Select(x => new DataEntry { ContractNumberTimberSales = x.ContractNumber, BidRate = x.VolumesRates.BidRate }).ToList();

            return View(dataEntries);
        }
    }
}
这是DataEntry类文件:

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace TimberSales.Models
{
    public class DataEntry
    {
        public string ContractNumberTimberSales { get; set; }
        public string LoggingUnit { get; set; }
        public string TractNumber { get; set; }
        public string Seller { get; set; }
        public string ApprovingOfficer { get; set; }
        public int NumBids { get; set; }
        public decimal TotalTractValue { get; set; }
        public decimal TotalTractVolume { get; set; }
        public Nullable<decimal> AcreageHarvested { get; set; }
        public string SilviculturalTreatment { get; set; }
        public string HarvestReason { get; set; }
        public Nullable<System.DateTime> BidDate { get; set; }
        public Nullable<System.DateTime> CutPayDate { get; set; }
        public Nullable<System.DateTime> ContractApprovedDate { get; set; }
        public Nullable<System.DateTime> ExtensionApprovedDate { get; set; }
        public Nullable<System.DateTime> ExtensionCuttingEndsDate { get; set; }
        public Nullable<System.DateTime> ExtentionExpirationDate { get; set; }
        public decimal EstimatedBidValue { get; set; }
        public decimal TotalAmountReceived { get; set; }
        public decimal AdminExpenseDeduction { get; set; }
        public decimal AdminExpenseDeductionPercent { get; set; }
        public Nullable<System.DateTime> SaleClosureDate { get; set; }
        public string Remarks { get; set; }
        public decimal ContractAmount { get; set; }
        public string ContractorName { get; set; }
        public virtual Contractor Contractor { get; set; }

        public int Species { get; set; }
        public int SawProduct { get; set; }
        public Nullable<decimal> EstimatedVolume { get; set; }
        public Nullable<decimal> ActualVolume { get; set; }
        public Nullable<decimal> BaseRate { get; set; }
        public Nullable<decimal> AppraisalRate { get; set; }
        public Nullable<decimal> AdvertisedRate { get; set; }
        public decimal BidRate { get; set; }
        public string ContractNumberVolumeRates { get; set; }
        public virtual SawProduct SawProduct1 { get; set; }
        public virtual Species Species1 { get; set; }
        public virtual TimberSale TimberSale { get; set; }
    }
}
TimberSales对象包含一个VolumeRates对象列表


我是否需要执行选择联接以访问我需要的信息,或者我是否可以在TimberSales中执行此操作。select语句显示我需要的信息,或者我是否需要在index.cshtml中修改@model IEnumerable?

要解决此问题,您正在尝试将集合推送到一个十进制的BidRate字段中。您需要使用FirstOrDefault或任何需要过滤的单一结果,将VolumeRates折叠为单个对象,然后获取BidRate:

List<DataEntry> dataEntries = timberSales.Select(x => new DataEntry { ContractNumberTimberSales = x.ContractNumber, BidRate = x.VolumesRates.FirstOrDefault().BidRate }).ToList();

容量是多少?那是收藏吗?这几乎就像你需要选择下成交量,比如first或default,然后获得BidRate,但我不能在不知道成交量是什么的情况下确定。这条线的目标是什么?列出dataEntries=timberSales.Selectx=>new dataEntries{ContractNumberMemberSales=x.ContractNumber,BidRate=x.VolumesRates.BidRate}.ToList@Radar5000我希望能够查看与合同相关的所有销售,并最终能够创建一个新的entry@SSharpVolumeRates是与类似的合同关联的销售,但您需要相应地筛选您的VolumeRates:List dataEntries=timberSales.Selectx=>new DataEntry{ContractNumberItemberSales=x.ContractNumber,BidRate=x.VolumesRates.FirstOrDefault.BidRate}.ToList;
List<DataEntry> dataEntries = timberSales.Select(x => new DataEntry { ContractNumberTimberSales = x.ContractNumber, BidRate = x.VolumesRates.FirstOrDefault().BidRate }).ToList();