开发者

The entity or complex type 'OurWebSiteModel.Article' cannot be constructed in a LINQ to Entities query

I wrote the following code to get articles from Entity Framework :

//return type of Items is 'IQueryable<Article>'
var articleToList = _articleRepo.Items;

var viewModel = new TopArticlesViewModel
{
    Articles =articleToList.Skip((page - 1) * PageSize).Take(PageSize),
    PagingInfo = new PagingInfo
    {
        CurrentPage = page,
        ItemsPerPage = PageSize,
        TotalItems = articleToList.Count()
    }
};

And here is the TopArticlesViewModel class definition :

 public class TopArticlesViewModel
    {
        public IQueryable<Article> Articles { get; set; }
        public PagingInfo PagingInfo { get; set; }
    }

But when I Run my application in asp.net mvc, i got this error :

The entity or complex type 'OurWebSiteModel.Article' cannot be constructed in a LINQ to Entities query. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupported开发者_运维技巧Exception: The entity or complex type 'OurWebSiteModel.Article' cannot be constructed in a LINQ to Entities query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜