Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7906885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:10:21+00:00 2026-06-03T11:10:21+00:00

I am curious on how to create a property that can be translated by

  • 0

I am curious on how to create a property that can be translated by LINQ. Below is a very simple example.

I have a table/class Category, that has a column ParentId linking to itself (So a category can have sub-categories)

EF automatically generates a property Category1, which is the parent category.

For the sake of clarity, I created another property

public partial class Category
{
  public Category Parent
  {
    get { return Category1; }
  }
}

The problem is, this works

var categs = ctx.Categories.Where(x => x.Category1 == null);

but this doesn’t work

var categs = ctx.Categories.Where(x => x.Parent == null);

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

Is there any way to create a translatable property (LINQ to SQL) without doing .ToList()?

EDIT: I want to avoid touching Model.edmx because the database often changes during development and the .edmx often needs to be recreated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T11:10:22+00:00Added an answer on June 3, 2026 at 11:10 am

    If you ask if it’s possible to create a property with any C# code in the getters/setters and later have it understood by standard LINQ to Entities – then no, it can’t be done. C# is much more expressive then SQL and it’s unreasonable to expect Entity Framework to act as a general C# to SQL translator.

    You can work around this is many cases though, see Using a partial class property inside LINQ statement for an example.

    Update

    It’d help if you told us what exactly you want to achieve, but here’s an example:

    public partial class Category
    {
        public static Expression<Func<Category, bool>> ParentIsNullExpression
        {
            get 
            {
                return c => c.Category1 == null;
            }
        }
    }
    

    And then

    var categs = ctx.Categories.Where(Category.ParentIsNullExpression);
    

    All sorts of manipulations on Expressions are possible, some of them are supported by EF and as such translate to SQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very curious, I have for example a app to localize our property,
I have been curious about dynamically create class at runtime in C# and stumbled
Pretty simple question. I have a model that has a property which is a
I have another rather curious problem. I have the following structure: CREATE TABLE [dbo].[Event]
Just curious. If you have 4Gb of free memory and you create 10k of
I'm curious what programming language I would have to learn in order to create
I have a WPF application where I'm trying to create a diagnostics panel that's
I'm curious as to whether one can define a Java class purely using a
I've noticed that some generated classes only declare class properties/variables via @property, and don't
I'm very curious as to why I need to create a custom MembershipProvider and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.