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();
usr.date_of_established
的类型是什么?无论如何,显式转换后跟 Convert 是多余的。此外:您通过此查询从数据库中获取了 所有customer_profiles
。ToList() 不是必需的。我敢打赌异常与日期时间有关。如果省略该行,它是否仍然发生? - Gert Arnold