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

  • Home
  • SEARCH
  • 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 7788607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:03:22+00:00 2026-06-01T21:03:22+00:00

i am developing an application in mvc3. I have two dropdowns and on the

  • 0

i am developing an application in mvc3.

I have two dropdowns and on the basis of value selected in first dropdown the second dropdown is populated.
The first dropdown is Course and on the basis of course selected the second dropdown populates the states where the course is available.

Foreg.if the course is ‘MCA’ the states should be Maharashtra,rajasthan and so-on.
For this i have written an ajax function which is working fine.
But the problem is i am not able to fetch multiple states at a time that is i can fetch only One state at a time.

I have written the following Code to fetch the state name:

HobbyHomeAdress Table contains ProvincialStateID which i fetch through some other method.
Then i compare that value with the value in ProvincialStateID in ProvincialState Table and fetch the data of that table but with it gives me the last record only.

 public ICollection<ProvincialState> FetchStateByStateid(ICollection<HobbyHomeAddress> hobbyhomeaddresslist)
    {
        log.Debug("Start");
        ISession session = DataAccessLayerHelper.OpenWriterSession();
        ITransaction transaction = session.BeginTransaction();
        ICollection<ProvincialState> provincialstate = null;
        try
        {
            foreach (var state in hobbyhomeaddresslist)
            {
                provincialstate = session.CreateCriteria(typeof(ProvincialState))
                                .Add(Expression.Eq("ProvincialStateID", state.ProvincialState.ProvincialStateID))
                                .List<ProvincialState>();
            }
            transaction.Commit();

        }
        catch (SessionException ex)
        {
            if (transaction != null && transaction.IsActive)
                transaction.Rollback();

            log.Error(ex);
            provincialstate = null;
        }
        finally
        {
            if (transaction != null)
                transaction.Dispose();

            if (session != null && session.IsConnected)
                session.Close();

            log.Debug("End");
        }
        return provincialstate;
    }
  • 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-06-01T21:03:24+00:00Added an answer on June 1, 2026 at 9:03 pm

    you are recreating the provincialstate collection for each state in hobbyhomeaddresslist. So you end up with a collection with a single entry, usually the last one. Instead you should create the collection upfront and after retrieving an item, just add it to that collection.

    …snip

        ...
        List<ProvincialState> provincialstate = new List<ProvincialState>();
        try
        {
            foreach (var state in hobbyhomeaddresslist)
            {
    
                var list = session.CreateCriteria(typeof(ProvincialState))
                                .Add(Expression.Eq("ProvincialStateID",       state.ProvincialState.ProvincialStateID))
                                .List<ProvincialState>();
                provincialstate.AddRange(list);
            }
            transaction.Commit();
    
        }
        ...
    

    Update: single query using a Disjunction.

        IList<ProvincialState> provincialstate = null;
        Disjunction dj = new Disjunction();    
        try
        {
            foreach (var state in hobbyhomeaddresslist)
            {
                dj.Add(Expression.Eq("ProvincialStateID",       state.ProvincialState.ProvincialStateID));
            }
            provincialstate = session.CreateCriteria(typeof(ProvincialState))
                           .Add(dj)
                           .List<ProvincialState>();
    
            transaction.Commit();
    
        }
    

    if you look at the generated SQL, you should now see a single select with several where clauses instead of several selects with a single where clause.

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

Sidebar

Related Questions

I am developing an MVC3 application using Visual Studio 2010. I have an aspx
we are developing a web application using MVC3 and VS2010. We have some pdf
we are developing a web application using MVC3 and Jquery. we have a situation
I have been developing an application in asp.net mvc3. We have used models to
I am currently developing a small application with EFCF (EF code first) and MVC3.
I am developing an MVC3 application and have been wondering about the following. Should
I'm developing an ASP MVC3 application and I have some views that are related
Hi Stack Community Members, I am developing an application under MVC3 where users have
I am developing an application in MVC3 which has dropdown lists on quite a
I am developing an MVC3 application in C#. The application has several projects. Since

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.