我面临一个编译时错误,如
Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.List<AnonymousType#2>'
这是我的代码:
var query = Enumerable.Repeat(new
{
Id = default(int),
Name = string.Empty,
type_id = default(int),
Ownername = string.Empty,
Ownermob = string.Empty,
ContactPerson = string.Empty,
ContactPersonmob = string.Empty,
Phone = string.Empty,
Mobile = string.Empty,
Room = string.Empty,
Build = string.Empty,
Road = string.Empty,
Area = string.Empty,
City = string.Empty,
country_id = default(int?),
state_id = default(int?),
Email = string.Empty,
Remark = string.Empty,
UserOFC = default(bool),
UserVAT = default(bool),
UserINV = default(bool),
UserNone = default(bool),
Username = string.Empty,
Register_Date = default(DateTime)},0).ToList();
query = db.Parties.Where(p => p.type_id.Equals(GroupByENTYPE)).OrderByDescending(p => p.Register_Date).Select(p => new
{
Id = p.Id,
Name = p.Name,
type_id = p.type_id,
Ownername = p.Ownername,
Ownermob = p.Ownermob,
ContactPerson = p.ContactPerson,
ContactPersonmob = p.ContactPersonmob,
Phone = p.Phone,
Mobile = p.Mobile,
Room = p.Room,
Build = p.Build,
Road = p.Road,
Area = p.Area,
City = p.City,
country_id = p.country_id,
state_id = p.state_id,
Email = p.Email,
Remark = p.Remark,
UserOFC = p.UserOFC,
UserVAT = p.UserVAT,
UserINV = p.UserINV,
UserNone = p.UserNone,
Username = db.Users.Where(u => u.Ref_no.Equals(p.User_id)).Select(u => u.Username).FirstOrDefault(),
Register_Date = p.Register_Date
}).FilterForColumn(ColumnName, SearchText).ToList();//here error occurs
}
这里用于声明常见查询部分并在多个条件下分配它。在FilterColumn部分编译时遇到错误。如何在另一页上同样的这种声明没有任何问题。
这里我把表格模式提供给知识:
----------------------更新--------------------- -------------------
Id int Unchecked
Name varchar(50) Unchecked
type_id int Unchecked
Ownername varchar(50) Checked
Ownermob nchar(10) Checked
Room varchar(10) Checked
Build varchar(50) Checked
Road text Checked
Area text Checked
City varchar(50) Checked
Phone nchar(10) Checked
Mobile nchar(10) Checked
Email varchar(100) Checked
ContactPerson varchar(50) Checked
ContactPersonmob nchar(10) Checked
UserOFC bit Checked
UserVAT bit Checked
UserINV bit Checked
UserNone bit Checked
state_id int Checked
country_id int Checked
Remark text Checked
Register_Date smalldatetime Unchecked
User_id char(14) Unchecked
请帮帮我......
答案 0 :(得分:0)
您的匿名类型的属性看起来完全相同,因此我最好的猜测是,您有一个默认类型与您使用对象时使用的实际类型不同。
我认为解决此问题的最佳策略是使用 Null Object pattern
资源:
答案 1 :(得分:0)
从纯文本中很难看出来。尝试使用二进制搜索来查找不兼容的属性。那就是