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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:27:27+00:00 2026-05-26T02:27:27+00:00

I am using DBContext API from EF 4.1. Consider following entity model (A, B,

  • 0

I am using DBContext API from EF 4.1.
Consider following entity model (A, B, E, D are entities)

A: aId

B: aId, cId

E: eId, aId

D: eId, cId, Data

What I want is equivalent of below sql query

SELECT
   B.aId,
   B.cId,
   COALESCE(M.Data, [default value])
FROM
   B LEFT OUTER JOIN
   (
      SELECT
         E.aId,
         D.cId,
         D.Data  
      FROM
         E INNER JOIN D ON E.eId = D.eId
   ) M
   ON B.aId = M.aId AND B.cId = M.cId

Its simple to have left join on B, E & D but I found that I cannot solve above query.
I have tried linq form of what I think would be an equivalent query

// inner join equivalent
var ee = db.E.Join(db.D, e => e.eId, d => d.eId,
    (e, d) => new { e.aId, e.eId, d.cId, d.Data });

// left outer join
var o = from c in db.B
        join e in ee on new { c.aId, c.cId }
            equals new { e.aId, e.cId } into temp
        from m in temp.DefaultIfEmpty()
        select new
        {
            c.aId,
            c.cId,
            Data = null != m ? m.Data : [default value]
        };

However, this fails when I call o.ToString() with following exception details:

System.ArgumentException: The argument to DbIsNullExpression must
refer to a primitive or reference type. at
System.Data.Common.CommandTrees.ExpressionBuilder.Internal.ArgumentValidation.ValidateIsNull(DbExpression
argument, Boolean allowRowType) at
System.Data.Objects.ELinq.ExpressionConverter.EqualsTranslator.CreateIsNullExpression(ExpressionConverter
parent, Expression input) at
System.Data.Objects.ELinq.ExpressionConverter.EqualsTranslator.TypedTranslate(ExpressionConverter
parent, BinaryExpression linq) at
System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter
parent, Expression linq)

… [more stack trace out here]

at
System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression
linq) at System.Data.Objects.ELinq.ExpressionConverter.Convert()
at
System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable1
forMergeOption) at System.Data.Objects.ObjectQuery.ToTraceString()
at System.Data.Entity.Internal.Linq.InternalQuery
1.ToString() at
System.Data.Entity.Infrastructure.DbQuery`1.ToString()

I have tried to form similar query using extension methods but had the same exception. What am I missing here?

———————————————————————————

EDIT:

It appears that issue was due to line

Data = null != m ? m.Data : [default value]

I have modified it to

   Data = m

And it started working. I have to move null checking logic at the place where I am using the result. Now, I am wondering what can be the cause of exception? From exception details, it appears that it cannot figure out m (which is an anonymous type) as reference type. Is this behavior documented somewhere?

  • 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-05-26T02:27:28+00:00Added an answer on May 26, 2026 at 2:27 am

    Well you were null checking a joined entity, which doesn’t make sense in terms of sql. The following should be interpreted properly as a coalesce:

    Data = m.Data ?? [default value]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using LINQ-to-Entities. Using the following query: var x = from u in context.Users
I am using Entity Framework and when a DbUpdateException is thrown from dbContext.SaveChanges() how
The goal: I'm trying to use the new Entity Framework 4.1 DbContext API (using
I created a model in the edm designer (VS10) using DbContext Entity Generator as
I am using Entity Framework 4.1 with POCOs and DbContext, no proxies no lazy
I'm using the DbContext and Code First APIs introduced with Entity Framework 4.1. The
I'm using the EF4.1 DbContext code generation, which creates POCO entities like this: public
I have this: public class DbContext : System.Data.Entity.DbContext, IDbContext { } My Ninject configuration:
I have the following query which I want to sort or filter using projected
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters

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.