Solved

LINQ Left Join Entity Framework 4

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

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.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

770 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