运营商&&'不能应用于'bool'和'System.Guid'类型的操作数 [英] Operator '&&' cannot be applied to operands of type 'bool' and 'System.Guid'
本文介绍了运营商&&'不能应用于'bool'和'System.Guid'类型的操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello All,
当我想从linq查询中获取值时,我收到错误。
错误如: - 运算符'&&'不能应用于'bool'和'System.Guid'类型的操作数
这是我的代码。
Hello All,
I am getting error when i want get values from linq query.
error like :- Operator '&&' cannot be applied to operands of type 'bool' and 'System.Guid'
Here is my code.
public DataTable getSalesByProperty(Guid propertyId)
{
try
{
DataTable dt = new DataTable();
DataColumn dc = new DataColumn();
dc.AutoIncrement = true;
dt.Columns.Add("salesId", typeof(Guid));
dt.Columns.Add("PropertyName", typeof(string));
dt.Columns.Add("ClientName", typeof(string));
dt.Columns.Add("MovedInDate", typeof(DateTime));
dt.Columns.Add("LeaseAmt", typeof(decimal));
dt.Columns.Add("CommissionPrcnt", typeof(decimal));
dt.Columns.Add("ComissionDlr", typeof(decimal));
var sls = (from s in tde.Sales
join p in tde.Properties on s.PropertyId equals p.PropertyId
where s.IsActive == true
&& (propertyId == Guid.Empty || s.PropertyId == propertyId)
select new
{
salesId = s.SaleId,
PropertyName = p.Name,
ClientName = s.Tenant1FirstName + " " + s.Tenant1LastName + " " + s.Tenant2FirstName + " " + s.Tenant2LastName + " " + s.Tenant3FirstName + " " + s.Tenant3LastName + " " + s.Tenant4FirstName + " " + s.Tenant4LastName,
MovedInDate = (DateTime?)s.DateTenantMovedIn ?? DateTime.Now,
LeaseAmt = s.LeaseAmt,
CommissionPrcnt = (decimal?)s.Commssion ?? 0,
ComissionDlr = (decimal?)s.FlatFee ?? 0
}).ToList();
sls.ToList().ForEach((n) =>
{
DataRow row = dt.NewRow();
row.SetField<Guid>("salesId", n.salesId);
row.SetField<string>("PropertyName", n.PropertyName);
row.SetField<string>("ClientName", n.ClientName);
row.SetField<DateTime>("MovedInDate", n.MovedInDate);
row.SetField<decimal>("LeaseAmt", n.LeaseAmt);
row.SetField<decimal>("CommissionPrcnt", n.CommissionPrcnt);
row.SetField<decimal>("ComissionDlr", n.ComissionDlr);
dt.Rows.Add(row);
});
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
当我设置guid.Empty属性时它会返回它抛出错误的值,如: -
Guid应包含32位数字和4个破折号(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)。
请尝试解决。
谢谢
When i set guid.Empty property then it does return values it throws error like :-
Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
Please try to resolve.
Thanks
推荐答案
var sls = from s in tde.Sales
join p in tde.Properties on s.PropertyId == p.PropertyId
where (s.IsActive) && ((propertyId == Guid.Empty) || (s.PropertyId == Guid.Parse(propertyId)))
// ...
可以解决您的问题。
may solve your problem.
这篇关于运营商&&'不能应用于'bool'和'System.Guid'类型的操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文