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

  • Home
  • SEARCH
  • 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 119307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:37:57+00:00 2026-05-11T03:37:57+00:00

I have been puzzling over a problem this morning with LinqToSQL. I’ll try and

  • 0

I have been puzzling over a problem this morning with LinqToSQL. I’ll try and summarise with the abbreviated example below to explain my point.

I have DB two tables:

table Parent {    ParentId }  table Child {    ChildId    ParentId [FK]    Name    Age } 

These have LinqToSQL equivalent classes in my project, however, I have written two custom model classes that I want my UI to use, instead of using the LinqToSQL classes.

My data access from the front end goes through a service class, which in turn calls a repository class, which queries the data via linq.

At the repository level I return an IQueryable by:

return from data in _data.Children        select new CustomModel.Child        {           ChildId = data.ChildId,           ParentId = date.ParentId        }; 

My service layer then adds an additional query restriction by parent before returning the list of children for that parent.

return _repository.GetAllChildren().Where(c => c.Parent.ParentId == parentId).ToList(); 

So at this point, I get the method has no supported translation to sql error when I run everything as the c.Parent property of my custom model cannot be converted. [The c.Parent property is an object reference to the linked parent model class.]

That all makes sense so my question is this:

Can you provide the querying process with some rules that will convert a predicate expression into the correct piece of SQL to run at the database and therefore not trigger an error?

I haven’t done much work with linq up to now so forgive my lack of experience if I haven’t explained this well enough.

Also, for those commenting on my choice of architecture, I have changed it to get around this problem and I am just playing around with ideas at this stage. I’d like to know if there is an answer for future reference.

Many thanks if anyone can help.

  • 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. 2026-05-11T03:37:57+00:00Added an answer on May 11, 2026 at 3:37 am

    Firstly, it begs the question: why is the repository returning the UI types? If the repo returned the database types, this wouldn’t be an issue. Consider refactoring so that the repo deals only with the data model, and the UI does the translation at the end (after any composition).


    If you mean ‘and have it translate down to the database’ – then basically, no. Composable queries can only use types defined in the LINQ-to-SQL model, and a handful of supported standard functions. Something similar came up recently on a related question, see here.

    For some scenarios (unusual logic, but using the typed defined in the LINQ-to-SQL model), you can use UDFs at the database, and write the logic yourself (in TSQL) – but only with LINQ-to-SQL (not EF).

    If the volume isn’t high, you can use LINQ-to-Objects for the last bit. Just add an .AsEnumerable() before the affected Where – this will do this bit of logic back in managed .NET code (but the predicate won’t be used in the database query):

    return _repository.GetAllChildren().AsEnumerable()             .Where(c => c.Parent.ParentId == parentId).ToList(); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 73k
  • Answers 73k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I don't think you can deploy a windows service via… May 11, 2026 at 1:51 pm
  • added an answer There is some process running at the time the interrupt… May 11, 2026 at 1:51 pm
  • added an answer Lots of reasons, but one of the biggest is that… May 11, 2026 at 1:51 pm

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.