Solved

LINQ Left Join Entity Framework 4

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…

863 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

26 Experts available now in Live!

Get 1:1 Help Now