Solved

LINQ Left Join Entity Framework 4

Posted on 2010-09-23
3
1,422 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
  • 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now