.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

clone object in linq to sql

Posted By:      Posted Date: October 21, 2010    Points: 0   Category :ASP.Net

I have two tables in the dbml, Table1 and Table2. Table1 has a Table1ID as primary key and Table2 has Table1ID as foreign key.

I have an instance of Table1 called table1,

Table1 table1 = new Table1();
table1.Table2 = new System.Data.Linq.EntitySet<Table2>();
table1.Table2.AddRange(table2List);          //table2List is a List<Table2>

then I create another instance of Table1 called anotherTable1,

Table1 anotherTable1 = Table1();               // clone
anotherTable1.Table2 = null;

At this point, my intention is to have table1 containing a list of Table2 and anotherTable1 containing 0 Table2. However, both table1.Table2 and anotherTable1.Table2 become 0 count.
Why is that? How to make it the way I wanted?



View Complete Post

More Related Resource Links

Urgent How to Create it ,Object Data Source ,Linq and sql or other any way


my query is



my data is

HR    HR    Rec    Records    Leave    Leave Records    HRL.0001    Policy and Process for leave record.    27.06.2010    30.06.2010    WIP    Edlink
HR    HR    Rec    Records    Leave    Leave Records    HRL.0002    Quarterly Review    01.07.2010    04.07.2010    Planned    Edlink
HR    HR    DB    Database    SAL    Salary    DDS.0001    Calculation of Monthly salary    08.08.2010    09.08.2010    WIP    Edlink
HR    HR    Rec    Records    Ind    Induction Records    HRI.0001    Completion of dossiers.    08.07.2010    10.07.2010  

Object Oriented Linq


Hello programmers,

I don't know if this is the right forum to post this in but here it goes anyway...

I am wondering into the unknown field of OOA and was looking for a way to separate my business logic from my UI. A small example is as followed:

Two DropDowns where the second one is depended on the selection in the first DropDown. You have Cars, planes, etc. inm the first DropDown and Toyota, Chrysler, etc in the second (depending on the value in the first DD.

I have som Lin syntax. The file is situated in the App_Code folder and NOT as code behind.

    public class GetProductCategoriesClass

        //Henter data fra databasen og gemmer det som ProductCategory
        public static List<ProductCategory> GetProductCategoriesMethod()
            DataClassesDataContext cate = new DataClassesDataContext();
            return (from p in cate.ProductCategories.ToList<ProductCategory>()
                    select p).ToList<ProductCategory>();


    public class GetProductSubCategoriesClass

        //Henter data fra databasen og gemmer det som ProductSubCategory
        public static List<ProductSubCategory> GetProductSubCategoriesMethod()
            DataClassesDataContext cate = new DataClassesDataContext();
            return (from p in cate.P

Unable to Create Object Variable for Linq Data Class


For some unknown reason I suddenly am unable to create an object variable for a Linq Data Class. If I create a new project and try the process again with the same database everything works as advertized.

The code I am using is Dim db As New RoggDataContext  which gives me an error on the object variable "db": Overload resolution failed because no accessibility 'NEW'  accepts this number of arguments.

I have looked inside every file in the Web Project like the web config to check the connection string, gobal, and designer.vb looking for any errors whit no JOY.  I also tried to create a new form and code behind with a button and received the same error.

This is mind blowing because as I already stated, I can create a new Web Site and the problem goes away.

Any help is appreciated!



How to make linq Object Serializable... 'System.Data.EnumerableRowCollection is not marked as Seriz


Dear All,

Is it possible to make the linq object as serializable. I need to pass the serialized Data as parameter to the Remoting Method.

My LinQ Query is as follows

 Dim LinqQuery = From R In dsEdit.Tables(0) _

                    Where R.Field(Of Integer)("ID") < 400 _

                    Select R


The Definition of ZipObject is as follows.



  Public Function ZipObject(ByVal obj As Object) As Byte()

        Dim ms

How to update value directly in class Object using Linq



I have a class object which is basically kind of hierarchy and looks like this when I convert that to XML.


  	<SKU>SKU 1</SKU> 
	<ConfigurationStatus>Not Configurable</ConfigurationStatus> 
  			<SKU>SKU 2</SKU> 
  			<ConfigurationStatus>Not Configurable</ConfigurationStatus> 
  					<SKU>SKU 3</SKU> 
		  			<ConfigurationStatus>Not Configurable</ConfigurationStatus> 



So you can see that I have "objectComponent" which is kind of hierarchy and that hierarchy can be upto any level.

Now I need to update <quantity> value where <sk

New Linq to Sql object crashing entire site


I have a site with many application roots below the main root

  • mainSite (application root)
    • admin
    • subfolder1
    • subfolder2 (application root)

I have a database connection saved in my database explorer that when test, does work.  I created a Linq to SQL in the subfolder2 application and the connection string is saved in /subfolder2/web.config.  This works absolutely perfectly.

Today I attempted to go in and create the admin page (as part of the primary root, but in a folder) for this newest subfolder application - like I have done a million times.  First I create the empty Linq to Sql object, everything continues to work.  But as soon as I add the table for the new application to the dbml, everything dies.  First I get the Custom Error screen telling me to turn off custom errors, and when I do,  I get the blank 500 server error on EVERY page, including html and css files, and not just in the root application, but in the nested applications as well.

First, what on Earth could possibly be so bad that IIS stops serving html files?

Second, why would the dbml editor allow me to add the table if there is something wrong with it?

Third, why is this functioning in other applications?  Is it some sort of duplicate nested information issue for either t

clone of object


i have an object and I'm trying to clone it:

Dim p As New BusinessLayer.DataContainer.oProduct
Dim v

Object Must Implement IConvertible error in LINQ to Entities with group by

1 down vote favorite

Hi. I have an ASP.NET MVC application in which i am using entity model for connecting to MySQl database

Here I am joining 2 tables and then applying group by on one of the fields. Then fetching the result from GroupBy result. Everything is working fine on development machine but getting  error:

"Object Must Implement IConvertible"   when executing on the stagging server.

Can you please help me out why such error is occurring. I have taken the dump of database form staging server and then used that on development machine then also working fine. But when I placed the dump of development machine database on staging then getting the same exception.

So where is problem i am not understanding.

The model structure is



Here student and st

No mapping exists from object type System.Xml.Linq.XDocument to a known managed provider native type



I am using XML in getting client data in 3-tier architecture, using XDocument in passing XML among layers.

But when I use it in inserting this XML in XDocument, it throws the following error:

No mapping exists from object type System.Xml.Linq.XDocument to a known managed provider native type. 

I am using the following code, it throws the exception at the bold line:

 public void DALInsertXML(XDocument x)
            SqlConnection connection = new SqlConnection(connection1);
            _command = ne

Playing with Linq grouping: GroupByMany?

One of its features is grouping. Many people understand grouping like it is defined in Sql. Linq is implementing grouping quite the same way. Let's discover this syntax and how to make consecutive groups easier.

LINQ : Implementing IN and NOT IN

I got tried of typing

var result = from s in source
where items.Contains(s)
select s;and so I implemented the IN and NOT IN methods as extension methods:

101 LINQ Samples Tutorials

101 LINQ Example with sample code snippets....This sample prints each element of an input integer array whose value is less than 5. The sample uses a query expression to create a new sequence of integers and then iterates over each element in the sequence, printing its value

Linq: how to share parameters between lambda expressions ?

When using Linq to objects, you will quickly feel the need to pass some parameters from a method to another but it's not so easy because each Linq method is not calling the following one. In a Linq sequence, each method is using the result computed by the previous one. So, local contexts are not visible from one method to another.
The compiler is using two technical different ways to let parameters go out of a method.

Linq to Sql CompiledQuery container

Ok now let's go. Here is just a little trick but with some interesting patterns that could be useful in some other contexts not connected to Linq to Sql.

When using Linq expressions, like with Linq to Sql, translating the expression into something else (sql for example) is taking time and resources. Sometimes it's negligible, sometimes not...

Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.

LINQ to SQL Paging using GridView in C# and ASP.NET 3.5

This tutorial will show you how we can extend the LINQ to SQL Class and create methods that will allow us to page data from a SQL database. C# version.

C# Object Oriented Programming

So far in C# Essentials we have looked at the basics of programming in C# such as variable types and flow control. Although it would be possible to write a functional program using these techniques, there is much more to becoming a proficient C# programmer. C# is, above all, an object oriented programming language and as such any C# programmer will be expected to create object-oriented applications using this language.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend