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 7602543
In Process

The Archive Base Latest Questions

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

Hi im trying to assign a default group to any user that registers with

  • 0

Hi im trying to assign a default group to any user that registers with my site. Since the admin Id of that group is the administrator, I query my database for a group with a admin id of my administrator and then assign that group to the user. However the following error is being thrown
“Unable to cast object of type ‘System.Data.Objects.ObjectQuery`1[DatabaseModel1.Group]’ to type ‘DatabaseModel1.Group’. ”
Heres the code

        Dim defaultGroup = (From group As Group In context.Groups
                     Where group.AdminID = ((From users As User0 In context.User0
                                            Where users.Name Like "Administrator"
                                            Select users.UserID).First)
                       Select group)

        currentUser.Groups.Add(defaultGroup)//the error is being thrown here

any help would be appreciated
Thanks

  • 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-30T23:26:17+00:00Added an answer on May 30, 2026 at 11:26 pm

    It sounds like you’ve got a query which can return multiple results, but you’re trying to assign it to a single-value variable.

    You probably just need to use something like:

    currentUser.Groups.Add(defaultGroup.First)
    

    The probable options are:

    • First() – allows multiple results and returns the first; will throw an exception if there are none
    • FirstOrDefault() – allows multiple results and returns the first; will return the default value for the element type (e.g. null) if there are no results
    • Last() – allows multiple results and returns the last; will throw an exception if there are none
    • LastOrDefault() – allows multiple results and returns the last; will return the default value for the element type (e.g. null) if there are no results
    • Single() – expects exactly one result; if there are no results or mulitple results, an exception is thrown

    Now that you’ve shown the query, it sounds like you should probably use a join rather than a nested query. I’m not hot on the VB query syntax, but in C# you might want:

    var defaultGroupQuery = 
            from group in context.Groups
            join user in context.User0 on group.AdminID equals user.UserID
            where user.Name == "Administrator"
            select group;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to assign the output of this command ( that is in my
I am trying to hide a checkbox and assign a default value of 1
I am trying to assign a custom eviction policy (default one's available being LRU/LFU)
So i'm trying to assign a hyperlink to a single word in a {p}
I am trying to assign objects in an NSMutableArray using this code - (IBAction)variablePressed:(UIButton
I'm trying to assign integer to a newly created row: INSERT INTO wcategory (name,
I'm trying to assign DataContext to a MenuItem, which is part of ListBox. <Style
I am currently trying to assign an event handler to dynamically created rectangle objects.
I am trying to assign a custom type as a key for std::map .
I'm trying to assign values contained in a lookup table to multiple variables by

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.