This project is read-only.

CategoryId is not supported in LINQ to Entities

Mar 2, 2010 at 12:25 AM

Dear Chris,

I think I'm facing one of the errors which you said you have fixed but I don't know which code I should change to fix it and how did you fix it so I fix it in the same way you did.The error is:

The specified type member 'CategoryId' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported

It appears when I click on one of the categories to open the related articles in BrowseArticles.aspx...

I think the following code (BrowseArticles.aspx code) is related to the problem:

if(LocalCategoryId > 0)

<font size="2" color="#0000ff"><font size="2" color="#0000ff">


lArticles = Articlerpt.GetArticlesByCategory(LocalCategoryId, PublishedOnly);


</font></font><font size="2" color="#0000ff">





Best Regards,


Mar 6, 2010 at 11:19 PM

I solved that problem already but I didn't use the same custom CategoryID.I think it was better if I could use the Custom CategoryID in the LINQ statement.

I wonder if there is away to do that?


Mar 21, 2010 at 4:20 PM

I suggest you to replace the p.CategoryId with p.Category.CategoryID


Mar 25, 2010 at 6:56 AM

That what I did but I mean it would be better if we can use the CategoryID directly.If you have worked on the same project can you help me to solve the following problem:

I added .rss to the IIS Mappings but it was no use I still get Page cannot be found?

Mar 27, 2010 at 4:51 PM

I guess I am not really sure what context you are using this reference, I could not find any code in the application to display a font block with inline styles. I could find a similar block in the BrowseArticles page that call the GetArticlesByCategoryId method. That method looks like this. And yes it references the CategoryId on the Category entity.

        public List<Article> GetArticlesByCategory(int CategoryId, bool PublishedOnly)

            var lArticles = new List<Article>();

            string key = CacheKey + "ByCategory_" + CategoryId + "_" + PublishedOnly;

            if (EnableCaching && (Cache[key] != null))
                return (List<Article>)Cache[key];

            //TODO: Change this to an IQueryable expression tree
            if (PublishedOnly)

                lArticles = (Articlesctx.Articles
                    .Where(p => p.Active).Where(p => p.Approved).Where(p => p.ExpireDate > DateTime.Now)
                    .Where(p => p.ReleaseDate <= DateTime.Now).Where(p => p.Category.CategoryID == CategoryId).OrderByDescending(
                    p => p.ReleaseDate).Select(lArticle => lArticle)).ToList();
                lArticles = (from lArticle in Articlesctx.Articles
                             where lArticle.Category.CategoryID == CategoryId
                             orderby lArticle.ReleaseDate descending
                             select lArticle).ToList();

            if (EnableCaching)
                CacheData(key, lArticles, CacheDuration);

            return lArticles;

Mar 27, 2010 at 7:57 PM

Thank you for replying to me and sorry about the fonts html code which was added by mistake while copying the code.The source code I downloaded for the method was p.CategoryId instead of p.Category.CategoryID.I don't know if the vesrion I have is the newest but as I mentioned before I correct it already but I was wondering why can't we use the custom CategoryID we made for the Article entity.