Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

LINQ Left Join Entity Framework 4

Posted on 2010-09-23
3
Medium Priority
?
1,435 Views
Last Modified: 2012-06-27
Hi,

I need all contacts from BRUGGE and value for KLNT_IsBlocked whether they are klant (customer) or not. My problem is that KLNT_IsBlocked isn't nullable or can be assigned a default value, how can I fix this?

 
Using _dmeContext

            Dim contactInfo = (From c In _dmeContext.Contact _
                               Group Join k In _dmeContext.Klant On _
                               c.CONT_ID Equals k.KLNT_CONT_ID _
                               Into results = Group _
                               From result In results.DefaultIfEmpty _
                               Select New With { _
                               .CONT_ID = c.CONT_ID, _
                               .CONT_Kenmerk = c.CONT_Kenmerk, _
                               .CONT_Straat = c.CONT_Straat, _
                               .CONT_StraatNr = c.CONT_StraatNr, _
                               .CONT_StraatBus = c.CONT_StraatBus, _
                               .CONT_Postcode = c.CONT_Postcode, _
                               .CONT_Gemeente = c.CONT_Gemeente, _
                               .KLNT_IsBlocked = result.KLNT_IsBlocked})
            Dim resInfo = From cont In contactInfo Where cont.CONT_Gemeente = "BRUGGE"
            dgvContactgegevens.DataSource = resInfo
        End Using

Open in new window


Error: The cast to value type 'Boolean' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.

0
Comment
Question by:MrFawlty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33743896
I'm not sure, but can you do something like this


Using _dmeContext

            Dim contactInfo = (From c In _dmeContext.Contact _
                               Group Join k In _dmeContext.Klant On _
                               c.CONT_ID Equals k.KLNT_CONT_ID _
                               Into results = Group _
                               From result In results.DefaultIfEmpty _
                               Select New With { _
                               .CONT_ID = c.CONT_ID, _
                               .CONT_Kenmerk = c.CONT_Kenmerk, _
                               .CONT_Straat = c.CONT_Straat, _
                               .CONT_StraatNr = c.CONT_StraatNr, _
                               .CONT_StraatBus = c.CONT_StraatBus, _
                               .CONT_Postcode = c.CONT_Postcode, _
                               .CONT_Gemeente = c.CONT_Gemeente, _
                               .KLNT_IsBlocked = result.KLNT_IsBlocked == null ? false : KLNT_IsBlocked })
            Dim resInfo = From cont In contactInfo Where cont.CONT_Gemeente = "BRUGGE"
            dgvContactgegevens.DataSource = resInfo
        End Using

Open in new window

0
 

Author Comment

by:MrFawlty
ID: 33744460
Hi,

Nope doesn't work at all:

Error      1      Expression expected.      
Error      2      'KLNT_IsBlocked' is not declared. It may be inaccessible due to its protection level.      
Error      3      Expression expected.
Error      4      Method arguments must be enclosed in parentheses.      
Error      5      'contactInfo' is not declared. It may be inaccessible due to its protection level.      
0
 

Accepted Solution

by:
MrFawlty earned 0 total points
ID: 33751677
Hi,

I think I've found a working solution:

javascript:document.getElementById('selector2').className='selectedAttach'; editCS('1081938', false, false);

This seems to do the trick.

Thanks for your suggestion though.
.KLNT_IsBlocked = CType(result.KLNT_IsBlocked, Boolean?)

Open in new window

0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this article, we’ll look at how to deploy ProxySQL.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question