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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:33:19+00:00 2026-05-31T22:33:19+00:00

I’m starting the development of a C#/ASP.net web app, within which I use the

  • 0

I’m starting the development of a C#/ASP.net web app, within which I use the Entity Framework (Microsoft ORM).

My problem is very simple :
In my default.aspx.cs I have this :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace Projet___TestConnaissances
{
    public partial class _Default : System.Web.UI.Page
    {
        protected List<Theme> lt = new List<Theme>();
        protected List<int> li = new List<int>();
        protected Theme th = new Theme();
        protected String test = "teeeest";
        protected int v = 1;

        protected void Page_Load(object sender, EventArgs e)
        {
            DataSourceContainer bdd = new DataSourceContainer();
            var requete = from Theme in bdd.ThemeSet select Theme;
            List<Theme> lt = requete.ToList(); // gets a list of themes
            v = lt.Count(); // puts in v the number of themes in lt
            th = lt.First(); // variable containing a unique theme (first of lt)
            test = "Ceci est un test";
            li.Add(1);
            li.Add(2);
            li.Add(3);
        }
    }
}

And in my default.aspx, I display this :

<p>
<br />test : <%= test %>
<br />v :  <%= v %>
<br />th.libelle : <%= th.libelle %>
<br />lt.count : <%= lt.Count() %>
<br />li.count : <%= li.Count() %>
</p>

As a result, I have :

test : Ceci est un test
v : 3
th.libelle : Test ajout libelle
lt.count : 0
li.count : 3

As you can see, my List of Theme is inexplicably reinitialized before its displayed.
What is weird is that my List of int is well kept, as well as the variable containing a unique theme.

The Theme class as been created with the Entity Designer, maybe this is the difference with the List of int ?

Thanks in advance to those who will help me figure out what’s happening there.
Bye !

  • 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-31T22:33:20+00:00Added an answer on May 31, 2026 at 10:33 pm

    Your Page_Load method is declaring a new variable called lt. It’s not assigning anything to the instance variable, because the local variable is shadowing the instance variable. So this:

    List<Theme> lt = requete.ToList();
    

    should probably be this:

    lt = requete.ToList();
    

    I’d also suggest using more meaningful variable names 🙂

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters 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.