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