3
System.Linq.IQueryable<CustomerProfile> query = 
    from usr in context.customer_profiles
    where usr.cust_email == LoginID
    select new CustomerProfile
    {
        NAME = usr.cust_name,
        CONTACT = usr.cust_contact,
        EMAILID = usr.cust_email,
        LOCATION = usr.cust_location,
        SERVICELOCATION=usr.cust_service_location,
        FAXNO=usr.cust_fax_no,
        FIRMNAME = usr.cust_firm_name,
        FIRMADDRESS = usr.cust_firm_address,
        DATEESTABLISHED = Convert.ToDateTime(((DateTime?)usr.date_of_established)),
        SIGNATURE = usr.cust_signature,
        LOGO =  usr.logo,
    };

在下一行,我得到“指定的演员表无效”的问题。我该如何纠正?

return query.ToList().FirstOrDefault(); 
4

2 回答 2

0

You are comparing a customers email to their login id in your query. I assume this would cause a casting issue, if not it probably wont return the correct results you want.

And use an implicit cast (var) rather than IQueryable

于 2012-05-05T08:54:40.473 回答
0

试试这个,然后返回查询。对不起格式,它让我感到忧郁

        CustomerProfile query =
         (from usr in context.customer_profiles
          where usr.cust_email == LoginID
          select new
          {
              NAME = usr.cust_name,
              CONTACT = usr.cust_contact,
              EMAILID = usr.cust_email,
              LOCATION = usr.cust_location,
              SERVICELOCATION = usr.cust_service_location,
              FAXNO = usr.cust_fax_no,
              FIRMNAME = usr.cust_firm_name,
              FIRMADDRESS = usr.cust_firm_address,
              DATEESTABLISHED = Convert.ToDateTime(((DateTime?)usr.date_of_established)),
              SIGNATURE = usr.cust_signature,
              LOGO = usr.logo,
          }).FirstOrDefault();
于 2012-05-10T19:00:38.387 回答