开发者

Can I improve read only perfomance using View on my DataBase and EF?

I use SQL 2008 Linq and Entity Framework 4开发者_高级运维.

In my DataBase I have a table called CmsContents. This table has many fields like Title, CategoryId and some pretty heavy like HtmlCode.

In many part of my Front end I need display only some field of my table CmsContents like example only the Title and CategoryId in descent order.

Question: Can I improve read only performance using a partial View for my Table CmsContents (that exclude the filed: HtmlCode)? So I would map this View to my Model in EF and query with Linq to get the desidred result in the front-end.

My aim is to improve performance and avoiding working with AnonymousType in my Linq to Entity queries.

Let me know what do you think.

Thanks for your help on this.


You can select only the fields you require, that way you would not need to load un-necessary data. It does not have to be anonymous. Example:

var result = from c in dbContext.CmsContents select new CmsContent
{Title = c.Title, CategoryId = c.CategoryId}

Edit: please try this on your code, this should work if your .CmsContents is IEnumerables, which I think it is.

    var contents = context.CmsGroupsTypes
.Single(g => g.GroupTypeId == 1)
.CmsContents
.Select(cms=>new CmsContent{Title = cms.Title, CategoryId = cms.CategoryId})
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜