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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:28:45+00:00 2026-06-17T11:28:45+00:00

i use entity framework and have the below code: public class AdvPackageInfo { private

  • 0

i use entity framework and have the below code:

public class AdvPackageInfo
{
    private int PackageId;
    private string Caption;
    private int Duration;
    private int Count;
    private bool Enable;
    private float Price;
}


 AdvertismentAgancyEntities enn = new AdvertismentAgancyEntities();

 List<AdvPackageInfo> lst = (from s in enn.Tbl_AdvPackage select new AdvPackageInfo { }).ToList();

    repeater1.DataSource = lst;
    repeater1.DataBind();

but it works just 1 time and when my page load for the second time it fails in execution and raise NullReferenceException…!!

according to this pag :
http://connect.microsoft.com/VisualStudio/feedback/details/663200/linq-to-entities-throws-nullreferenceexception-when-the-output-attribute-set-is-empty
it’s dot net framework problem.

i try this code too :

var q = (from s in enn.AdvPackage select s).toList();

but it doesn’t work either.

is there any better way to make a linq select to a list????

  • 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-17T11:28:45+00:00Added an answer on June 17, 2026 at 11:28 am

    Instead of this line:

    List<AdvPackageInfo> lst = 
        (from s in enn.Tbl_AdvPackage select new AdvPackageInfo { }).ToList();
    

    You could do this:

    var lst = new List<AdvPackageInfo>();
    for (int i = 0; i < enn.Tbl_AdvPackage.Count(); i++)
        lst.Add(new AdvPackageInfo());
    

    (Note that the suggested workaround in the MS Connect page is wrong. Using Enumerable.Repeat will create a list full of references to a single object)


    Update per comment below:
    If you’re just trying to load the datagrid, then you just need to retrieve the list as:

    var lst = enn.Tbl_AdvPackage.ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use entity framework and have a set of users: public class DbModel :
I have several Entity Framework Code First DbContext objects that use a custom Initializer.
I use Entity Framework with ASP.NET MVC3 Code First. I have a project entity
I use Entity Framework 4 and I have parent - child relation with Cascade
I use ADO.NET Entity-Framework, I have a page that is data-bound to an entity
I'm using Entity Framework and I have a custum IQueryProvider. I use the Execute
I have converted an Entity framework project to use POCO objects by removing the
I use Entity Framework code-first. DataBaseName - I want to create a database in
Using Code First Entity Framework with .NET MVC 4 I have created a new
We use Entity Framework 5, but have a requirement to ALSO use a normal

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.