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

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

Linq to SQL does not implement System.Collections.IEnumerable

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

I am having a lot of the same issue as this poster did with errors on initializing type.

I am trying to learn linq and am about ready to give up - don't get how this is easier...Yell

I'm trying to do a simple update to product names in the product table based on the manufacturer ID

In order to do this I am looping through each record.  I was initally successful with changing all names in the column but when I try to query the data, I continually run into multiple problems.


The following poster has had the same issue I have but his solution isn't working for me. 


I keep getting the same error on the opening bracket on the select statement in the SelectByManufacturerID function...

Error 1 Cannot initialize type 'DataBaseDataManagement.ProductName' with a collection initializer because it does not implement 'System.Collections.IEnumerable'


Button that does the actual updating...

        protected void btnQuery_Click(object sender

View Complete Post

More Related Resource Links

Using the generic type 'System.Collections.Generic.IEnumerable' requires '1' type arguments



I'm trying to create a control out of a class I found, and one of the overridden functions is the following:

protected override void PerformDataBinding(IEnumerable data)

However, when I try to build the control I'm getting the error as shown in the subject. I've tried searching, and it seems the signature for the original function matches the one I have, and all other solutions I've seen uses the same signature.

Anyone able to help out?

The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced. You must



This is frustrating, and I don't know how to solve it.

I have a strange problem. I am adding a LinqDatasource object, and set the context:

        protected void LinqDataSource_ContextCreating(object sender, LinqDataSourceContextEventArgs e)
            e.ObjectInstance = new KaruselaDataContext(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

Then I get this error:
The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'.


On web.config I already have this:
<add assembly="System.Data.Linq, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

NOTE: The datacontext is in a different project (DLL proect) where I added a refernce to System.Data.Linq.

is there another way adding a refernce to a web project? or only though teh web.config?


System.Xml.Linq.XElement and XPathDocument


I have an XPathDocument that I want to save to a table using LINQ, but I get this error

cannot implicitly convert type 'System.Xml.XPath.XPathDocument' to 'System.Xml.Linq.XElement'

I create the XPathDocument from some (valid) xml contained in a resource file

XPathDocument xDoc = new XPathDocument(new StringReader(Resource1.TestXML));

when I try to assign it with LINQ, it flags up an error

NewDataItem.XML = xDoc  ----  error here

NewDataitem is a LINQ to SQL object created from the underlying table, 'NewDataItem.XML' is a column type of 'XML'

how do i (easily) convert xDoc so I can pass it into the LINQ object ?

Serializing objects which implement IEnumerable<>

Hi, I'm trying for long time to serialize an object which contains an object which implements IEnumerable<>. The last object also contains an object which implements IEnumerable<>. The objects strucutre is as followed: [Serializable] public class A { public B _b {get; set; } } [Serializable] public class B : IEnumerable<C> { public List<C> c_items {get; set;} public void Add (C obj){} } [Serializable] public class C : IEnumerable<D> { public List<D> d_items {get; set;} public void Add (D obj){} } [Serializable] public class D { public int Key {get; set;} public int Value {get; set;} } In the code line: A obj = new A(); XmlSerializer serializer = new XmlSerializer(obj.GetType()); I'm getting the exception: unable to generate temporary class (result=1), error CS0030: Cannot convert type 'C' to type 'D'... When I remove the IEnumerable implementation from one of B or C, the serialization works. What as I getting wrong? Any help would be appreciated!

The type or namespace name 'Linq' does not exist in the namespace 'System'

Hi, I uploaded my website to the server, and I have there a working with wcf - it should be fw 3.5 I saw that fw 3.5 is installed on the server and also we have there fw 3.0 sp1. I run my website : www.qenglishcenter.com and I'm getting an error : The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) shouldn't System.linq be already existed ? Thanks for any reply.  

Sharepoint site collections accessible only by system account

I I have setup a VM to start palying with SP development, everything running under administrator (sql, sharepoint services....). After succefully creating the root on port 80 and a couple of site collections, whenever I shoot IE http://mymoss or any othe site collection, I go right away to the web site without the usual authentification dialog box. On the right jand side, I see I am logged in as "System account". When I try to "sign in as a different user", enter domain\administrator, who is owner, the dialog box just keeps coming back and I can not log. . Thanks in advance

Question on WCF service with Linq to SQL on 64-bit system

I'm trying this question one more time since I realized the work in in a 64-bit environment. I have a WCF service which runs in production in a 32-bit environment using VS2008 and .NET 2.0. We made a big change to our environment (lots at the same time) and I moved the services to VS2010, .NET 4.0, and 64-bit processes.  I wrote a new service and deployed it under IIS.  If I browse to the service I get the example screen and clicking on the link gives me the metadata.  So all of that is working. In my services I create a Linq to SQL context, perform a query, then return the result set as an Array.  I wrapped the context creation with a using.  My tests returned an exception "Attempt to access an object that has already been disposed".  I traced it down and found that the code executes, forces the query, returns the results, exits the using statement (disposing the context properly) then exits the method.  The next thing I get is the exception, inside framework code, and it is linq code attempting to fulfill the query once again. I have searched until I'm blue in the face trying to find prior incidents and fixes but all I found was one post, two years ago, same problem with less debugging, and no answer to the problem other than 'don't use the using statement' which is a bad suggestion.  So for a work around I wrote a Co

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

'ToList' is not a member of 'System.Collections.IList'



I am trying to cast a collection of IList object but why I get this error message "'ToList' is not a member of 'System.Collections.IList'"

The DataRecords1() function below works but not the DataRecords2() function.

Public Function DataRecords1() As IList

Dim dataInformation = From xyz In _DBContextTable1

Return dataInformation.ToList() 'works
End Function

Public Function DataRecords2() As IList
Dim dataInformation As IList

dataInformation = From xyz In _DBContextTable1

Return dataInformation.ToList() 'not working Sad
End Function



System.Collections.Concurrent vs. System.Collections.Generic.SynchronizedCollection

I'm confused why there is a "thread safe" collection in Collections.Generic.SynchronizedCollection and an entire namespace devoted to concurrent collections.   What is the difference?

Read CSV using Linq - System.IndexOutOfRangeException


I'm trying to get data from a CSV file and add it directly into a database using Linq.

I'm using the following code:

Dim dataImport = From line As String In File.ReadLines("c:\temp\test.csv").Skip(1)
		Let CR = line.Split(Chr(124)) _
		Select New [property] With { _
		.ADDRESS_1 = CR(0), _
		.ADDRESS_2 = CR(1), _
		.ADDRESS_3 = CR(2) _

The code works if I remove all the but the first property e.g.

Dim dataImport = From line As String In File.ReadLines("c:\temp\test.csv").Skip(1)
		Let CR = line.Split(Chr(124)) _
		Select New [property] With { _
		.ADDRESS_1 = CR(0) _

But then I get the old "System.IndexOutOfRangeException: Index was outside the bounds of the array." exception when adding more columns. 

I really want to get this working...

Any ideas?

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

system.linq.enumerable.where Issue



I have a table "OSTAN" with two columns "ID" (Key index) and "NAME". I am trying to  construct a linq query to select the Name for a specific ID. I have not luck trying to construct the where clause. Here what I have so far:


using (XeledsEntities db = new XeledsEntities())
            string SelectedName = db.Ostans.Name.Where( Ostan=> Ostan.Equals(Request.QueryString["Ostan"])).FirstOrDefault(); 


Can anybody help me construct this where clause to set the Selected Name?




I'm really struggling with Linq in my controller, i was helped with my last problem but now i have the following problem with the following error:


My code is:


           var CList = (from d in List1
                        select d);
           foreach (var d in CList) ;




I've tried adding ToList(), .AsEnumerable() etc but still cannot get it to return list of data which is countries.

If i put Response.Write(CList.Count()) i get correct number of records 64

If i put a breakpoint on var CList, i can see the data in List1, but CList has a value of null

Can anyone see my problem






Can anyone see where i'm going wrong here as i get the following in my view:


My code is:


public ActionResult Index()
            List<GetCurrencyCountriesDataFieldsFromDB> List1 = new List<GetCurrencyCountriesDataFieldsFromDB>();
            List<GetCurrencyRatesFromDatabase> List2 = new List<GetCurrencyRatesFromDatabase>();

            _IGCFDB.GetCurrencyFromDataBase(List1, List2);

            var rate = from c in List2 where c.DboCurrency.Contains("GBP") select c;

            this.ViewData["Test"] = rate;

            return View();


and in view i have




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.
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