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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:35:38+00:00 2026-05-21T04:35:38+00:00

I have created a new query like the following var pressData = from press

  • 0

I have created a new query like the following

var pressData = from press in dataContext.Releases
                                select new
                                {
                                    Heading = press.Heading,
                                    Description = press.Desc,
                                    DatePublished = press.PublishDate.ToString(),
                                    Body = press.BodyContent,
                                    ID=press.ReleaseID,
                                    CreatedBy=press.CreatedBy
                                };

Later in the code I want to update the entity from a session variable, but not save any data back to the database. Here is the code I am trying to accomplish this with….

var edit = pressData.Where(a => a.Heading == sectionPreview.HeadingContent && a.ID == sectionPreview.tionID).FirstOrDefault();
                            if (edit != null)
                            {
                               //WONT LET ME UPDATE THE Body VALUE
                                edit.Body = sectionPreview.SectionContent;

                            }

The code aboves purpose is to look at pressData and replace the body content with the new body from a session variable(not shown here), but NOT save it to the db. I want pressData to be filtered and updated only in the entity. So when I bind it to the control in this case it binds the data stored in my session.

 this.rptSections.DataSource = pressData;
                this.rptSections.DataBind();

I am getting a complier error stating
Property or indexer ‘AnonymousType#1.Body’ cannot be assigned to — it is read only.

I checked the entity model and nothing is read only not any fields not anything. I must be missing something?

  • 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-21T04:35:39+00:00Added an answer on May 21, 2026 at 4:35 am

    Anonymous Types encapsulate a read only property collection – for more information, read here. The compiler rewrites anonymous types as a constructor injections, ie:

    select new
    {
        Heading = press.Heading,
        Description = press.Desc,
        DatePublished = press.PublishDate.ToString(),
        Body = press.BodyContent,
        ID=press.ReleaseID,
        CreatedBy=press.CreatedBy
    };
    

    Is really rewritten as:

    new Anonymous`1(press.Heading, press.Desc, press.PublishDate.ToString(), press.BodyContent, press.ReleaseID, press.CreatedBy)
    

    And the properties are read only (public get, private / protected set, to use an easy comparison). If you want to solve your issue, instead of taking the data and making an anonymous object, create a real type and set properties on it.

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

Sidebar

Related Questions

I have following query: var result = ( from role in db.Roles join user
We have created a new List View Style that shows thumbnails from a picture
I have created a new solution with a minimal amount of code that represents
I m new to use ankhSVN and having issues. I have created some new
Does a new SessionFactor y and Session object have to be created for each
I have an NSArray and I'd like to create a new NSArray with objects
I have a simple SQL query: Select ID, COUNT(ID) as Selections, OptionName, SUM(Units) as
How to create new PCL file similar to existing MS doc. I have MS
I have some code that creates a new site in SharePoint. Upon browsing to
I have a migration that runs an SQL script to create a new Postgres

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.