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 8055747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:29:20+00:00 2026-06-05T08:29:20+00:00

I have this problem: The Vehicle type derives from the EntityObject type which has

  • 0

I have this problem:
enter image description here

The Vehicle type derives from the EntityObject type which has the property “ID”.

I think i get why L2S can’t translate this into SQL- it does not know that the WHERE clause should include WHERE VehicleId == value. VehicleId btw is the PK on the table, whereas the property in the object model, as above, is “ID”.

Can I even win on this with an Expression tree? Because it seems easy enough to create an Expression to pass to the SingleOrDefault method but will L2S still fail to translate it?

I’m trying to be DDD friendly so I don’t want to decorate my domain model objects with ColumnAttributes etc. I am happy however to customize my L2S dbml file and add Expression helpers/whatever in my “data layer” in the hope of keeping this ORM-business far from my domain model.

Update:

I’m not using the object initialization syntax in my select statement. Like this:

private IQueryable<Vehicle> Vehicles() 
{
    return from vehicle in _dc
        select new Vehicle() { ID = vehicle.VehicleId };
}

I’m actually using a constructor and from what I’ve read this will cause the above problem. This is what I’m doing:

private IQueryable<Vehicle> Vehicles() 
{
    return from vehicle in _dc
        select new Vehicle(vehicle.VehicleId);
}

I understand that L2S can’t translate the expression tree from the screen grab above because it does not know the mappings which it would usually infer from the object initialization syntax. How can I get around this? Do I need to build a Expression with the attribute bindings?

  • 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-05T08:29:22+00:00Added an answer on June 5, 2026 at 8:29 am

    I have decided that this is not possible from further experience.

    L2S simply can not create the correct WHERE clause when a parameterized ctor is used in the mapping projection. It’s the initializer syntax in conventional L2S mapping projections which gives L2S the context it needs.

    Short answer – use NHibernate.

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

Sidebar

Related Questions

I have this problem I can't figure out, I query the DB this way:
I have this problem and I can't seem to find on the Internet for
I have this problem with probing integer from TempData as it sees DempData[sth] as
I have this problem. Have a banner which is code with AS3, and our
I have this problem that drives me mad, so I am here to ask
I have this problem with a lot of arrays in my program, and I
I have this problem with saving a date into a MySQL database. I have
I have this problem: Well, the words in the article are ClickableSpans that change
I have this problem where I open Visual Studio and the internal windows are
i have this problem to find a particular xml node l have post this

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.