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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:04:05+00:00 2026-05-31T11:04:05+00:00

My code like this: private void BindGvUsersInRole () { var aRole = (from aspnet_Roles

  • 0

My code like this:

    private void BindGvUsersInRole ()
    {
        var aRole =
            (from aspnet_Roles rol
                 in _allRoles
            where rol.RoleId.ToString() == ddlRoles.SelectedValue
            select rol).SingleOrDefault();

        this.gvUsersInRole.DataSource = aRole.aspnet_Users;
        this.gvUsersInRole.DataBind();
    }

I got an error on the last line:

Exception Details: System.InvalidOperationException: The result of a query cannot be enumerated more than once.

then I amend the function like this(thanks @VitaliyKalinin):

private void BindGvUsersInRole ()
{
    Guid  roleID=new Guid(ddlRoles.SelectedValue);

    var users =
    (
        from aspnet_Roles rol in _allRoles
        from u in rol.aspnet_Users
        where rol.RoleId == roleID
        select u
    ).ToList();

    this.gvUsersInRole.DataSource = users;
    this.gvUsersInRole.DataBind();
}

STILL SAME ERROR!!!!

what happens!?!?

the “aspnet_Users” property :

    /// <summary>
    /// 没有元数据文档可用。
    /// </summary>
    [XmlIgnoreAttribute()]
    [SoapIgnoreAttribute()]
    [DataMemberAttribute()]
    [EdmRelationshipNavigationPropertyAttribute("realtydbModel", "aspnet_UsersInRoles", "aspnet_Users")]
    public EntityCollection<aspnet_Users> aspnet_Users
    {
        get
        {
            return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<aspnet_Users>("realtydbModel.aspnet_UsersInRoles", "aspnet_Users");
        }
        set
        {
            if ((value != null))
            {
                ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<aspnet_Users>("realtydbModel.aspnet_UsersInRoles", "aspnet_Users", value);
            }
        }
    }
  • 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-31T11:04:07+00:00Added an answer on May 31, 2026 at 11:04 am

    You can use Single or SingleOrDefault() todo this:

    // parse the string `ddlRoles.SelectedValue` into the appropriate type as `roleID`
    var roleID = ParseRoleID(ddlRoles.SelectedValue);
    var aRole = (from rol in aspnet_Roles.Include("aspnet_Users")
                where rol.RoleId == roleID 
                select rol).Single();
    

    However this will throw an exception if there is more than one entity returned. If you just want the first entity that matches the case you can use First()or FirstOrDefault():

    var roleID = ParseRoleID(ddlRoles.SelectedValue);
    var aRole = (from rol in aspnet_Roles.Include("aspnet_Users")
                where rol.RoleId == roleID 
                select rol).First();
    

    The OrDefaultversions of these methods make sure you don’t get an exception if there is no match. It will return null instead.

    Also:
    Rather than using ToString() on the RoleId parse the ddlRoles.SelectedValue into the appropriate type before you use it in the LINQ query since some methods (ToString() is one of them) are not supported within a LINQ query that executes against a DB.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code like this: private var video:Video; ... private function init():void { ...
Quite often in my GUI code, I write something like this: private void SecondTimer_Elapsed(object
I typically have code like this on a form: private void PerformLongRunningOperation() { BackgroundWorker
In my code I have something like this: private void doSomething() { Calendar today
let's say we have some simple code like this : private static void Main()
My code currently looks like this: private Foo myFoo; public Foo CurrentFoo { get
There's some code in our project that looks a bit like this: Private Sub
Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName
I would like to try this code: public struct Direction { private int _azimuth;
Many beginning programmers write code like this: sub copy_file ($$) { my $from =

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.