試圖返回實體選定字段,但得到的錯誤無法隱式轉換類型「System.Collections.Generic.List」到「System.Collections.Generic.List <Model.Room
我的接口
public interface IRoomRepository
{
List<Room> All();
Room Get(int id);
Room Add(Room obj);
void Delete(Room obj);
void Update(Room obj);
}
我的倉庫,我實現IRoomRepository
public List<Room> All()
{
using (HotelEntities db = new HotelEntities())
{
var result = from room in db.Rooms
select new
{
room.RoomNumber,
room.Id,
room.RoomType
};
return result.ToList();
}
}
收到以下錯誤
無法隱式轉換類型 'System.Collections.Generic.List <>' 到 'System.Collections.Generic.List'
編輯
房型號
類namespace Model
{
using System;
using System.Collections.Generic;
public partial class Room
{
public int Id { get; set; }
public string RoomNumber { get; set; }
public Nullable<int> RoomTypeId { get; set; }
public Nullable<int> RoomStatusId { get; set; }
public virtual RoomStatus RoomStatus { get; set; }
public virtual RoomType RoomType { get; set; }
}
}
你所有的()方法返回一個非客房類型其只能從房間返回3個屬性,並非所有的 – BugFinder