无法将类型...隐式转换为...问题
我有这个代码:
public static IEnumerable<dcCustomer> searchCustomer(string Companyname)
{
TestdbDataContext db = new TestdbDataContext();
IEnumerable<dcCustomer> myCustomerList = (from Customer res
in db.Customers
where res.CompanyName == Companyname
select res);
return myCustomerList;
}
无论我尝试什么,我都会不断收到转换错误。
Error 1 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<ConnectionWeb.Customer>' to 'System.Collections.Generic.IEnumerable<ConnectionWeb.DAL.dcCustomer>'. An explicit conversion exists (are you missing a cast?) \\srv01\home$\Z****\Visual Studio 2008\Projects\ConnectionWeb\ConnectionWeb\DAL\dcCustomer.cs 63 20 ConnectionWeb
我想尝试让 myCustomerList 将值保留在枚举器中并返回它。
I have this code:
public static IEnumerable<dcCustomer> searchCustomer(string Companyname)
{
TestdbDataContext db = new TestdbDataContext();
IEnumerable<dcCustomer> myCustomerList = (from Customer res
in db.Customers
where res.CompanyName == Companyname
select res);
return myCustomerList;
}
And whatever i try i keep getting the convert error.
Error 1 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<ConnectionWeb.Customer>' to 'System.Collections.Generic.IEnumerable<ConnectionWeb.DAL.dcCustomer>'. An explicit conversion exists (are you missing a cast?) \\srv01\home$\Z****\Visual Studio 2008\Projects\ConnectionWeb\ConnectionWeb\DAL\dcCustomer.cs 63 20 ConnectionWeb
I want to try get myCustomerList to keep the values in an enumerator and return it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是您期望返回
DAl.dcCustome
r 类型,但 linq 语句返回ConnectionWeb.Customer
类型...您可以通过更改来解决此问题:
至:
HTH
the problem is the you are expecting to return a
DAl.dcCustome
r type, but the linq statement is returning aConnectionWeb.Customer
type...You could overcome this by changing:
to:
HTH
在我看来, db.Customers 包含 ConnectionWeb.Customer 类型的对象,而不是像您假设的那样 ConnectionWeb.DAL.dcCustomer 。
Looks to me like db.Customers contains objects of type ConnectionWeb.Customer and not ConnectionWeb.DAL.dcCustomer like you assume.