models层
public class BlogEntity
{
public int ID { get; set; }
public string COLName { get; set; }
} public interface ICOLRepository {
IList<COL> ListAll();
} public class COLRepository : ICOLRepository {
private DataClasses1DataContext _dataContext; public COLRepository() {
_dataContext = new DataClasses1DataContext();
} #region IMovieRepository Members public IList<BlogEntity> ListAll()
{
var BlogEntity= from m in _dataContext.COL
select new { m.COLName,m.ID}; return BlogEntity.ToList(); return BlogEntity.ToList<BlogEntity>();
} #endregion
}返回应该怎么写BlogEntity.ToList()和BlogEntity.ToList<BlogEntity>();都出错
public class BlogEntity
{
public int ID { get; set; }
public string COLName { get; set; }
} public interface ICOLRepository {
IList<COL> ListAll();
} public class COLRepository : ICOLRepository {
private DataClasses1DataContext _dataContext; public COLRepository() {
_dataContext = new DataClasses1DataContext();
} #region IMovieRepository Members public IList<BlogEntity> ListAll()
{
var BlogEntity= from m in _dataContext.COL
select new { m.COLName,m.ID}; return BlogEntity.ToList(); return BlogEntity.ToList<BlogEntity>();
} #endregion
}返回应该怎么写BlogEntity.ToList()和BlogEntity.ToList<BlogEntity>();都出错
select new { m.COLName,m.ID};这儿查出来的跟你的实体并不一致吧,这儿只有两列
{
public string COLName { get; set; }
} public interface ICOLRepository {
IList<BlogEntity> ListAll();
} public class COLRepository : ICOLRepository {
private DataClasses1DataContext _dataContext; public COLRepository() {
_dataContext = new DataClasses1DataContext();
} #region IMovieRepository Members public IList<BlogEntity> ListAll()
{
var BlogEntity = from m in _dataContext.COL
select new { m.COLName}; return BlogEntity.ToList(); //return BlogEntity.ToList<BlogEntity>();
} #endregion
}
返回值应该怎么写呢
return _dataContext.COL.ToList();