Linq to SQL: object.Tolist manipulation not possible

Posted on 2008-10-01
Medium Priority
Last Modified: 2013-11-11
When I try to work with the returned list from the query i can't change it's property
While the class has a get and set property

even when i create a copy i cant change the polygon property is there a way to create a copy without the readonly property.

so i can use the changed data further in my code

Thanks in advance
===========APPLICATION CODE============
 Dim cityList = (From c In cities _
        Select c.name, c.polygon).Take(100).ToList
        Dim point As New ArrayList()
        '..... some manipulation                
        cityList(i).polygon = point
        Catch ex As Exception
        End Try
===========MAPPING CLASS==============
<Column(Storage:="_polygon", AutoSync:=AutoSync.Always, DbType:="NVarChar(MAX)", IsDbGenerated:=true, UpdateCheck:=UpdateCheck.Never)>  _
	Public Property polygon() As String
			Return Me._polygon
		End Get
			If (String.Equals(Me._polygon, value) = false) Then
				Me._polygon = value
			End If
		End Set
	End Property

Open in new window

Question by:stoffel_cc
  • 2
LVL 64

Accepted Solution

Fernando Soto earned 1000 total points
ID: 22617190
Hi stoffel_cc;

When you declare the query as you did and make the Select clause with just the two properties, the Select clause make the Anonymous type Read-Only

Dim cityList = (From c In cities _
                Select c.name, c.polygon).Take(100).ToList

When you make the Select clause as in the following the properties are now read/write

Dim cityList = (From c In cities _
                Select New With { c.name, c.polygon }).Take(100).ToList

In the following Select Clause the property with the key word Key is Read-Only whilw the other is read/write

Dim cityList = (From c In cities _
                Select New With { c.name, Key c.polygon }).Take(100).ToList


LVL 64

Expert Comment

by:Fernando Soto
ID: 22624471
Hi stoffel_cc;

have you tried my solution?


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
When you have multiple client accounts to manage, it often feels like there aren’t enough hours in the day. With too many applications to juggle, you can’t focus on your clients, much less your growing to-do list. But that doesn’t have to be the cas…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question