?
Solved

LINQ Left Join Entity Framework 4

Posted on 2010-09-23
3
Medium Priority
?
1,445 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 using thread_statistics can cause high memory usage.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

749 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