英文:
How do I resolve CS1941 Error in LINQ, C#
问题
我尝试了这个查询,但是它给我返回了CS1941错误。
错误图片:
![错误图片][1]
ReportList = from hb in (new XPQuery<HallBanquet>(das.UOW))
join hbi in (new XPQuery<HallBanquetItem>(das.UOW)) on hb.DocId equals hbi.HallBanquet
join cus in (new XPQuery<Customer>(das.UOW)) on hb.Customer equals cus.MastId
select new
{
hb.DocId,
hb.Site,
hb.DocNo,
hb.RefNo,
hb.DocDt,
hb.Customer,
hb.NoOfPax,
hb.PartyDate,
hb.FromTime,
hb.ToTime,
hb.MainMenu,
hb.OfferPackage,
hb.Currency,
hb.CurRate,
hb.LPONo,
hb.LPODate,
hb.ExpectedDeliveryDt,
hb.RoundOff,
hb.SubTotal,
hb.NetAmount,
hb.Remarks,
hbi.SeqNo,
hbi.HallBanquet,
hbi.ItemType,
hbi.Code,
Desc = hbi.Description,
hbi.Item,
hbi.Pkg,
hbi.Unit,
hbi.Qty,
hbi.Price,
hbi.Cost,
hbi.DiscountPer,
hbi.DiscountAmt,
hbi.Amount,
hbi.TotalAmt,
hbi.IsInclussiveTax,
hbi.TaxCd,
hbi.TaxPer,
hbi.TaxAmt,
hbi.GlCode,
cus.Description
};
错误出现在第二行的`join`语句。
[1]: https://i.stack.imgur.com/2cyEV.png
1. HallBanquet 类:
```csharp
public class HallBanquet : Epimonos.BizObjects.Core.XPDocumentObject
{
// 类的定义,请保留原始代码
}
```
2. HallBanquetItem 类(子表):
```csharp
public class HallBanquetItem : XPDocumentDet
{
// 类的定义,请保留原始代码
}
```
3. Customer 表:
```csharp
public class Customer : Epimonos.BizObjects.Core.XPMasterObject
{
// 类的定义,请保留原始代码
}
```
英文:
I am trying this query but it gives me CS1941 Error.
Image of error:
ReportList = from hb in (new XPQuery<HallBanquet>(das.UOW))
join hbi in (new XPQuery<HallBanquetItem>(das.UOW)) on hb.DocId equals hbi.HallBanquet
join cus in (new XPQuery<Customer>(das.UOW)) on hb.Customer equals cus.MastId
select new
{
hb.DocId,
hb.Site,
hb.DocNo,
hb.RefNo,
hb.DocDt,
hb.Customer,
hb.NoOfPax,
hb.PartyDate,
hb.FromTime,
hb.ToTime,
hb.MainMenu,
hb.OfferPackage,
hb.Currency,
hb.CurRate,
hb.LPONo,
hb.LPODate,
hb.ExpectedDeliveryDt,
hb.RoundOff,
hb.SubTotal,
hb.NetAmount,
hb.Remarks,
hbi.SeqNo,
hbi.HallBanquet,
hbi.ItemType,
hbi.Code,
Desc = hbi.Description,
hbi.Item,
hbi.Pkg,
hbi.Unit,
hbi.Qty,
hbi.Price,
hbi.Cost,
hbi.DiscountPer,
hbi.DiscountAmt,
hbi.Amount,
hbi.TotalAmt,
hbi.IsInclussiveTax,
hbi.TaxCd,
hbi.TaxPer,
hbi.TaxAmt,
hbi.GlCode,
cus.Description
};
The error is thrown on the second line at join
-
HallBanquet Class :
public class HallBanquet : Epimonos.BizObjects.Core.XPDocumentObject
{
public HallBanquet(Session session) : base(session)
{
// This constructor is used when an object is loaded from a persistent storage.
// Do not place any code here.
}
public override void AfterConstruction()
{
base.AfterConstruction();
// Place here your initialization code.
}
public override void Initialize(RstUser LoginUser, RstSite LoginSite)
{} public override void AfterDisplay(RstUser LoginUser, RstSite LoginSite) { UpdateTotals(); } private Customer _Customer; [RValidate("Customer", true, 0)] public Customer Customer { get { return _Customer; } set { SetPropertyValue<Customer>(nameof(Customer), ref _Customer, value); if (!IsLoading && !IsSaving) { this.Branch = null; this.Contact = null; //this.Currency = GetCompanyCurrency(this.Site.Company); this.Currency = Site?.Company?.CompanyCurrencies.FirstOrDefault(e => e.Currency == this.Customer?.Currency); } } } private CustomerBranch _Branch; [RValidate("Branch", false, 0)] public CustomerBranch Branch { get { return _Branch; } set { SetPropertyValue<CustomerBranch>(nameof(Branch), ref _Branch, value); if (!IsLoading && !IsSaving) { this.Contact = null; } } } private CustomerContact _Contact; [RValidate("Contact",false,0)] public CustomerContact Contact { get { return _Contact; } set { SetPropertyValue<CustomerContact>(nameof(Contact), ref _Contact, value); } } private string _ContactTel; public string ContactTel { get { return _ContactTel; } set { SetPropertyValue<string>(nameof(ContactTel), ref _ContactTel, value); } } private decimal _NoOfPax; [RValidate("NoOfPax", true, 0)] public decimal NoOfPax { get { return _NoOfPax; } set { SetPropertyValue<decimal>(nameof(NoOfPax), ref _NoOfPax, value); } } private DateTime _PartyDate = DateTime.Today; public DateTime PartyDate { get { return _PartyDate; } set { SetPropertyValue<DateTime>(nameof(PartyDate), ref _PartyDate, value); } } private DateTime _FromTime = DateTime.Parse("12:00"); public DateTime FromTime { get { return _FromTime; } set { SetPropertyValue<DateTime>(nameof(FromTime), ref _FromTime, value); } } private DateTime _ToTime=DateTime.Parse("12:00"); public DateTime ToTime { get { return _ToTime; } set { SetPropertyValue<DateTime>(nameof(ToTime), ref _ToTime, value); } } private FoodPkg _MainMenu; [RValidate("MainMenu", true, 0)] public FoodPkg MainMenu { get { return _MainMenu; } set { SetPropertyValue<FoodPkg>(nameof(MainMenu), ref _MainMenu, value); } } private string _OfferPackage; [Size(50)] public string OfferPackage { get { return _OfferPackage; } set { SetPropertyValue<string>(nameof(OfferPackage), ref _OfferPackage, value); } } private RstCompanyCurrency _Currency; [RValidate("Currency", true, 0 )] public RstCompanyCurrency Currency { get { return _Currency; } set { SetPropertyValue<RstCompanyCurrency>(nameof(Currency), ref _Currency, value); if (!IsLoading && !IsSaving) { this.CurRate = value == null ? 0 : value.CurRate; } } } private Double _CurRate; [CustomValidation(typeof(VcCommon), "ValidateCurrencyRate")] public Double CurRate { get { return _CurRate; } set { SetPropertyValue<Double>(nameof(CurRate), ref _CurRate, value); } } private string _LPONo; [Size(50)] [RValidate("LPO No", false ,50 )] public string LPONo { get { return _LPONo; } set { SetPropertyValue<string>(nameof(LPONo), ref _LPONo, value); } } private DateTime _LPODate = DateTime.Today; public DateTime LPODate { get { return _LPODate; } set { SetPropertyValue<DateTime>(nameof(LPODate), ref _LPODate, value); } } private DateTime _ExpectedDeliveryDt; public DateTime ExpectedDeliveryDt { get { return _ExpectedDeliveryDt; } set { SetPropertyValue<DateTime>(nameof(ExpectedDeliveryDt), ref _ExpectedDeliveryDt, value); } } private Decimal _CustomerBalance; [NonPersistent] public Decimal CustomerBalance { get { return _CustomerBalance; } set { SetPropertyValue<Decimal>(nameof(CustomerBalance), ref _CustomerBalance, value); } } private Decimal _RoundOff; [CustomValidation(typeof(VcCommon), "ValidateRoundOff")] public Decimal RoundOff { get { return _RoundOff; } set { SetPropertyValue<Decimal>(nameof(RoundOff), ref _RoundOff, value); UpdateTotals(); } } private Decimal _SubTotal; public Decimal SubTotal { get { return _SubTotal; } set { SetPropertyValue<Decimal>(nameof(SubTotal), ref _SubTotal, value); } } private Decimal _NetAmount; public Decimal NetAmount { get { return _NetAmount; } set { SetPropertyValue<Decimal>(nameof(NetAmount), ref _NetAmount, value); } } private string _Remarks; [Size(SizeAttribute.Unlimited)] public string Remarks { get { return _Remarks; } set { SetPropertyValue<string>(nameof(Remarks), ref _Remarks, value); } } [DevExpress.Xpo.Association("HallBanquet-Item"), Aggregated()] public XPCollection<HallBanquetItem> HallBanquetItems { get { XPCollection<HallBanquetItem> col = GetCollection<HallBanquetItem>(nameof(HallBanquetItems)); if (col.Sorting.Count == 0) { col.Sorting.Add(new DevExpress.Xpo.SortProperty("SeqNo", SortingDirection.Ascending)); } return col; } } public void UpdateTotals() { if (IsLoading || IsSaving) return; Decimal netAmt = 0; Decimal taxAmt = 0; foreach (var item in this.HallBanquetItems) { if (!item.IsDeleting) { netAmt += item.TotalAmt; } } _NetAmount = CommonFx.Round((netAmt + this.RoundOff), this.Currency?.Currency); _SubTotal = CommonFx.Round((netAmt-taxAmt), this.Currency?.Currency); } }
-
HallBanquetItem Class (Child Table)
public class HallBanquetItem : XPDocumentDet
{
public HallBanquetItem(Session session) : base(session)
{
// This constructor is used when an object is loaded from a persistent storage.
// Do not place any code here.
}public override void AfterConstruction() { base.AfterConstruction(); // Place here your initialization code. } private HallBanquet _HallBanquet; [Association("HallBanquet-Item")] public HallBanquet HallBanquet { get { return _HallBanquet; } set { SetPropertyValue<HallBanquet>(nameof(HallBanquet), ref _HallBanquet, value); } } private RstConstants _ItemType; public RstConstants ItemType { get { return _ItemType; } set { SetPropertyValue<RstConstants>(nameof(ItemType), ref _ItemType, value); ItmTypeDs = value?.Description; } } private string ItmTypeDs { get; set; } private string _Code; [Size(50)] //[RValidate("Code", true, 50)] public string Code { get { return _Code; } set { SetPropertyValue<string>(nameof(Code), ref _Code, value); } } private string _Description; [Size(200)] //[RValidate("Description", true, 200)] public string Description { get { return _Description; } set { SetPropertyValue<string>(nameof(Description), ref _Description, value); } } private Guid _Item; public Guid Item { get { return _Item; } set { SetPropertyValue<Guid>(nameof(Item), ref _Item, value); } } private float _Pkg = 1; public float Pkg { get { return _Pkg; } set { SetPropertyValue<float>(nameof(Pkg), ref _Pkg, value); } } private string _Unit; [Size(50)] //[RValidate("Unit", true,50 )] public string Unit { get { return _Unit; } set { SetPropertyValue<string>(nameof(Unit), ref _Unit, value); } } private Decimal _Qty = 1; public Decimal Qty { get { return _Qty; } set { SetPropertyValue<Decimal>(nameof(Qty), ref _Qty, value); SetTaxAndSalesAmount(); } } private Decimal _Price; public Decimal Price { get { return _Price; } set { SetPropertyValue<Decimal>(nameof(Price), ref _Price, value); SetTaxAndSalesAmount(); } } private float _Cost; public float Cost { get { return _Cost; } set { SetPropertyValue<float>(nameof(Cost), ref _Cost, value); } } private Decimal _DiscountPer; public Decimal DiscountPer { get { return _DiscountPer; } set { SetPropertyValue<Decimal>(nameof(DiscountPer), ref _DiscountPer, value); this.DiscountAmt = Math.Round(((Price * Qty) * value) / 100, 3, MidpointRounding.AwayFromZero); } } private Decimal _DiscountAmt; public Decimal DiscountAmt { get { return _DiscountAmt; } set { SetPropertyValue<Decimal>(nameof(DiscountAmt), ref _DiscountAmt, value); SetTaxAndSalesAmount(); } } private Decimal _Amount; public Decimal Amount { get { return _Amount; } set { SetPropertyValue<Decimal>(nameof(Amount), ref _Amount, value); } } private Decimal _TotalAmt; public Decimal TotalAmt { get { return _TotalAmt; } set { SetPropertyValue<Decimal>(nameof(TotalAmt), ref _TotalAmt, value); } } private Boolean _IsInclussiveTax; public Boolean IsInclussiveTax { get { return _IsInclussiveTax; } set { SetPropertyValue<Boolean>(nameof(IsInclussiveTax), ref _IsInclussiveTax, value); } } private Tax _TaxCd; public Tax TaxCd { get { return _TaxCd; } set { SetPropertyValue<Tax>(nameof(TaxCd), ref _TaxCd, value); this.TaxPer = value == null ? 0 : value.TaxValue; } } private Decimal _TaxPer; public Decimal TaxPer { get { return _TaxPer; } set { SetPropertyValue<Decimal>(nameof(TaxPer), ref _TaxPer, value); SetTaxAndSalesAmount(); } } private Decimal _TaxAmt; public Decimal TaxAmt { get { return _TaxAmt; } set { SetPropertyValue<Decimal>(nameof(TaxAmt), ref _TaxAmt, value); } } private Account _GlCode; public Account GlCode { get { return _GlCode; } set { SetPropertyValue<Account>(nameof(GlCode), ref _GlCode, value); } } private void SetTaxAndSalesAmount() { if (!IsLoading && !IsSaving) { this.TaxAmt = Math.Round(CommonFx.GetTaxAmount(this.IsInclussiveTax, this.TaxPer, ((this.Price * this.Qty) - this.DiscountAmt)), 3); this.Amount = Math.Round(CommonFx.GetTaxableAmount(this.IsInclussiveTax, this.TaxPer, ((this.Price * this.Qty) - this.DiscountAmt)), 3); this.TotalAmt = Math.Round(CommonFx.GetAmountWithTax(this.IsInclussiveTax, this.TaxPer, ((this.Price * this.Qty) - this.DiscountAmt)), 3); } } }
-
Customer Tabe
public class Customer : Epimonos.BizObjects.Core.XPMasterObject
{public Customer(Session session) : base(session) { // This constructor is used when an object is loaded from a persistent storage. // Do not place any code here. } public override void AfterConstruction() { base.AfterConstruction(); // Place here your initialization code. } public override void Initialize(RstUser LoginUser, RstSite LoginSite) { _VATRegion = VATRegion.Domestic; } public override void AfterDisplay(RstUser LoginUser, RstSite LoginSite) { ///Value assigned after display } #region Properties private string _ShortDs; [Size(10)] [RValidate("Short Description",true ,10 )] public string ShortDs { get { return _ShortDs; } set { SetPropertyValue<string>(nameof(ShortDs), ref _ShortDs, value); } } private CustomerGroup _Parent; public CustomerGroup Parent { get { return _Parent; } set { SetPropertyValue<CustomerGroup>(nameof(Parent), ref _Parent, value); } } private RstCurrency _Currency; public RstCurrency Currency { get { return _Currency; } set { SetPropertyValue<RstCurrency>(nameof(Currency), ref _Currency, value); } } private string _IDNumber; [Size(50)] [RValidate("ID. Number",false , 50)] public string IDNumber { get { return _IDNumber; } set { SetPropertyValue<string>(nameof(IDNumber), ref _IDNumber, value); } } private string _CustomerType; [Size(30)] [RValidate("CustomerType",false, 30)] public string CustomerType { get { return _CustomerType; } set { SetPropertyValue<string>(nameof(CustomerType), ref _CustomerType, value); } } [NonPersistent] private RstBaseType _BaseType; public RstBaseType BaseType { get { return _BaseType; } set { SetPropertyValue<RstBaseType>(nameof(BaseType), ref _BaseType, value); } } private VATRegion _VATRegion; public VATRegion VATRegion { get { return _VATRegion; } set { SetPropertyValue<VATRegion>(nameof(VATRegion), ref _VATRegion, value); } } private string _VATNumber; [Size(50)] [RValidate("VAT Number",false , 50)] public string VATNumber { get { return _VATNumber; } set { SetPropertyValue<string>(nameof(VATNumber), ref _VATNumber, value); } } private DateTime _VATStartDt; public DateTime VATStartDt { get { return _VATStartDt; } set { SetPropertyValue<DateTime>(nameof(VATStartDt), ref _VATStartDt, value); } } private DateTime _ContractExpiry = DateTime.Today; public DateTime ContractExpiry { get { return _ContractExpiry; } set { SetPropertyValue<DateTime >(nameof(ContractExpiry), ref _ContractExpiry, value); } } private bool _ShowPriceInDN; public bool ShowPrice { get { return _ShowPriceInDN; } set { SetPropertyValue<bool>(nameof(ShowPrice), ref _ShowPriceInDN, value); } } /// <summary> /// Mannual blocking of Customer from Transaction /// </summary> _BlockCustomer private bool _BlockCustomer; public bool BlockCustomer { get { return _BlockCustomer; } set { SetPropertyValue<bool>(nameof(BlockCustomer), ref _BlockCustomer, value); if (!IsLoading && !IsSaving && !BlockCustomer) _BlockedReason = ""; } } private string _BlockedReason; [Size(100)] [RValidate("Blocked Reason",false ,100 )] public string BlockedReason { get { return _BlockedReason; } set { SetPropertyValue<string>(nameof(BlockedReason), ref _BlockedReason, value); } } private string _PaymentTerms; [Size(30)] [RValidate("Payment Terms",false , 30)] public string PaymentTerms { get { return _PaymentTerms; } set { SetPropertyValue<string>(nameof(PaymentTerms), ref _PaymentTerms, value); } } private string _DeliveryTerms; [Size(30)] [RValidate("DeliveryTerms",false , 30)] public string DeliveryTerms { get { return _DeliveryTerms; } set { SetPropertyValue<string>(nameof(DeliveryTerms), ref _DeliveryTerms, value); } } private Account _CustomerLedger; public Account CustomerLedger { get { return _CustomerLedger; } set { SetPropertyValue<Account>(nameof(CustomerLedger), ref _CustomerLedger, value); } } private Account _AdvanceLedger; public Account AdvanceLedger { get { return _AdvanceLedger; } set { SetPropertyValue<Account>(nameof(AdvanceLedger), ref _AdvanceLedger, value); } } private Boolean _IsSubCustomer; public Boolean IsSubCustomer { get { return _IsSubCustomer; } set { SetPropertyValue<Boolean>(nameof(IsSubCustomer), ref _IsSubCustomer, value); if (!IsLoading && !IsSaving && !IsSubCustomer) _ParentCustomer = null; } } private Customer _ParentCustomer; public Customer ParentCustomer { get { return _ParentCustomer; } set { SetPropertyValue<Customer>(nameof(ParentCustomer), ref _ParentCustomer, value); } } private bool _IsCreditLimitCheck; public bool IsCreditLimitCheck { get { return _IsCreditLimitCheck; } set { SetPropertyValue<bool>(nameof(IsCreditLimitCheck), ref _IsCreditLimitCheck, value); if (!IsCreditLimitCheck) { _CreditPeriod = 0; _CreditLimit = 0; } } } private int _CreditPeriod; public int CreditPeriod { get { return _CreditPeriod; } set { SetPropertyValue<int>(nameof(CreditPeriod), ref _CreditPeriod, value); } } private Decimal _CreditLimit; public Decimal CreditLimit { get { return _CreditLimit; } set { SetPropertyValue<Decimal>(nameof(CreditLimit), ref _CreditLimit, value); } } private SalesMan _SalesMan; public SalesMan SalesMan { get { return _SalesMan; } set { SetPropertyValue<SalesMan>(nameof(SalesMan), ref _SalesMan, value); } } #endregion #region Associations [Association("Customer-CustomerBranch")] public XPCollection<CustomerBranch> CustomerBranches { get { XPCollection<CustomerBranch> col = GetCollection<CustomerBranch>(nameof(CustomerBranches)); if (col.Sorting.Count == 0) { col.Sorting.Add(new DevExpress.Xpo.SortProperty("SeqNo", SortingDirection.Ascending)); } return col; } } private XPCollection<CustomerBranch> _ActiveBranches; public XPCollection<CustomerBranch> ActiveBranches { get { return _ActiveBranches; } } [Association("Customer-CustomerContact")] public XPCollection<CustomerContact> CustomerContacts { get { XPCollection<CustomerContact> col = GetCollection<CustomerContact>(nameof(CustomerContacts)); if (col.Sorting.Count == 0) { col.Sorting.Add(new DevExpress.Xpo.SortProperty("SeqNo", SortingDirection.Ascending)); } return col; } } public XPCollection<CustomerContact> ActiveCustContacts(Guid? BranchID) { if (BranchID != null) { return new XPCollection<CustomerContact>(this.Session, CriteriaOperator.Parse($"Customer = '{this.MastId}'AND Active AND CustomerBranch.RowId='{BranchID}' "), new SortProperty("SeqNo", SortingDirection.Ascending)); } else { return new XPCollection<CustomerContact>(this.Session, CriteriaOperator.Parse($"Customer = '{this.MastId}'AND Active"), new SortProperty("SeqNo", SortingDirection.Ascending)); } } #endregion }
答案1
得分: 1
在第2行,你可能应该写hb.DocId equals hbi.HallBanquetId
或者hb.DocId equals hbi.DocId
,而不是hb.DocId equals hbi.HallBanquet
(这取决于你的外键从项目指向宴会的命名方式)。
英文:
Probably, in the 2nd line you should write hb.DocId equals hbi.HallBanquetId
or hb.DocId equals hbi.DocId
instead of hb.DocId equals hbi.HallBanquet
(It depends on how your foreign key pointing from item to banquet is named).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论