Click here to Skip to main content
15,914,820 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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.

XML
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
Posted
Updated 3-Dec-13 3:20am
v2
Comments
[no name] 3-Dec-13 8:30am    
try to use and instead of && and or instead od ||
phil.o 3-Dec-13 10:06am    
[quote]Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).[/quote]
What is the type of propertyId variable? How is it initialized?
Mukesh Bhagat 3-Dec-13 10:23am    
It is type of guid data type of property id.
phil.o 3-Dec-13 10:51am    
How is it initialized?

1 solution

C#
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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Dec-13 9:40am    
A fix, a 5. :-)
—SA
phil.o 3-Dec-13 10:03am    
Thanks Serguey, that's so valuable a 5 from you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900