Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6702587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:04:16+00:00 2026-05-26T07:04:16+00:00

Basically I have the follwing: Dim ctx As New AdminCoreEntities Dim roles = (From

  • 0

Basically I have the follwing:

Dim ctx As New AdminCoreEntities
Dim roles = (From r In ctx.Roles where r.Name.StartsWith("cust") Select r) 'list of System.Linq.IQueryable(Of AdminCoreModel.Role)

 Dim items = From i In ctx.QuickLinks.Include("Roles")
             Where (i.TenantID = "470556ba-3574-4b01-a619-b85e9721b966" AndAlso i.Roles.Contains(roles))
             Select New With {
                               i.ID,
                               i.Name,
                               .Roles = (From r In i.Roles Select New With {.Id = r.ID, .Name = r.Name})
                              }

The error i get when i run this is:

Unable to cast object of type System.Data.Objects.ObjectQuery`1[AdminCoreModel.Role] to type AdminCoreModel.Role

Basically I have a many to many situation and I try to get all the Quicklinks objects queried by their roles
and not quite sure why EF will cast to a single AdminCoreModel.Role when i.Roles is a collections of objects.

Any help greatly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:04:17+00:00Added an answer on May 26, 2026 at 7:04 am

    Well, .Contains() expects one Role, and you’re passing it a list. That’s what the error says.

    Try (apologies in advance if I mangle the VB.NET syntax; I don’t usually write VB.NET):

    Dim ctx As New AdminCoreEntities
    Dim items = From i In ctx.QuickLinks  ' You don't need Include because you're projecting.
                Where (i.TenantID = "470556ba-3574-4b01-a619-b85e9721b966" 
                       AndAlso i.Roles.Any(Function(role) role.Name.StartsWith("cust"))
                Select New With {
                                    i.ID,
                                    i.Name,
                                     .Roles = (From r In i.Roles Select New With {.Id = r.ID, .Name = r.Name})
                              }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any name for the following DB table design: Basically we have generic
I have the following Soap Request I receive from the client, where basically I
I have the following 2 queries: SELECT CARD_ID,COUNT(CARD_ID) AS CNT1 FROM G_CARD_SCHEDULE GROUP BY
So basically I have the following code: Dim myIE As InternetExplorer: Set myIE =
I have the following jsfiddle setup: http://jsfiddle.net/5bFq7/8/ basically I have a ul list and
I basically have the following flow: XML -> JSON -> Spring MVC -> jsp
I basically have the following string in the format: A,B,C:D,E,F What I am trying
Basically I have the following class: class StateMachine { ... StateMethod stateA(); StateMethod stateB();
I've been battling to get this right...basically I have the following HTML setup: <div
i have the following jquery code. basically i will have several overlapped divs and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.