我在 .net 4.5 上使用 MVC。
我已将模型从网站分离到类库中,并将 .edmx 的 tt 类文件复制到我的网站,以便我可以访问模型类。
尽管当我像这样从库中返回一些数据时,
List<website.Class1> a = objLibraryRef.GetFileLists1();
我收到这个错误。
Cannot convert type 'System.Collections.Generic.List<website.Class1>'
to 'System.Collections.Generic.List<library.Class1>'
我不想引用类库来访问模型类。
如有任何帮助,我们将不胜感激。 谢谢和干杯。
最佳答案
您的 DAL 方法正在返回 List<T>
类型 Class1
这是在 library
命名空间,同时将其分配给 Class1
类型但它的命名空间不同,即 website1
不是 library
.
您可以使用隐式类型变量来推断 DAL 库方法返回的类型:
var list = objLibraryRef.GetFileLists1();
或者如果你真的想要 website.Class1
类型的列表然后你必须按照@adricadar 在他的帖子中建议的那样再次投影到列表上。
关于c# - 无法将类型 'System.Collections.Generic.List<website.Class1>' 转换为 'System.Collections.Generic.List<library.Class1>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30613326/