linq

What's the best way to copy and insert data from related tables into a new set of related tables with Linq

I work on a web game , I use asp.net mvc, linqtosql. I have 3 tables that store default game values: DefaultRegions, DefaultSubRegions and DefaultCountries. These 3 tables are related to each other thanks to primary / foreign keys. I need to copy the values of these tables into 3 tables called Regions, SubRegions and Countries when som...

How do you skip default value columns on insert/update in Linq To SQL?

How do you insert/update a column through Linq To SQL and Linq To SQL use the default values? In particular I'm concerned with a timestamp field. I've tried setting that column to readonly and autogenerated, so it stopped trying to put in DateTime.MinValue, but it doesn't seem to be updating on updates. ...

Which is fastest? Data retrieval...

Is it quicker to make one trip to the database and bring back 3000+ plus rows, then manipulate them in .net & LINQ or quicker to make 6 calls bringing back a couple of 100 rows at a time? ...

dbmetal visual metal error:"magma string must not be empty"

i am just trying to generate the classes for linq to mysql with dbmetal / visual metal and keep running into the error: "magma string must not be empty"... i've googled, i've recompiled locally, checked the references etc. and don't really want to start debugging this... anybody had the same issue before or knows of another way to genera...

How to Convert all strings in List<string> to lower case using LINQ?

Hi all, I saw a code snippet yesterday in one of the responses here on StackOverflow that intrigued me. It was something like this: List<string> myList = new List<string> {"aBc", "HELLO", "GoodBye"}; myList.ForEach(d=>d.ToLower()); I was hoping I could use it to convert all items in myList to lowercase. However, it doesn't happen...

How do I build a Linq Expression Tree that compares against a generic object?

I have an IQueryable and an object of type T. I want to do IQueryable().Where(o => o.GetProperty(fieldName) == objectOfTypeT.GetProperty(fieldName)) so ... public IQueryable<T> DoWork<T>(string fieldName) where T : EntityObject { ... T objectOfTypeT = ...; .... return SomeIQueryable<T>().Where(o => o.GetProperty(fi...

Is there a LINQ library for C++?

Are there any Platform agnostic (not CLI) movements to get LINQ going for C++ in some fashion? I mean a great part of server frameworks around the world run on flavors of UNIX and having access to LINQ for C++ on UNIX would probably make lots of people happy! ...

Service linq to sql

Can anyone suggest good article on services over linq to sql ? ...

LINQ to SQL multiple DataContext-s

I'm trying to figure the best strategy about how to organize DataContexts. The typical DB we work has between 50 and 100 tables usually in third-normal form and with many relations between them. I think we have two options: Put all tables in a single context. This will ensure that anything we do will be committed in the correct order i...

Keep ConnectionString in LINQ designer file

Whenever I drop a new database object from server explorer into the dbml, Visual Studio replaces the connection string in the designer file with a new one that it automatically adds to the connection strings in my config file. They both have exactly the same parameters, just different names. How do I force Visual Studio to use and keep ...

Linq DataContext class not accessible in my MVC after I save the dbml

I just downloaded MVC and I am going through a tutorial. Everything goes fine until I try to declare a DataContext object. My dbml is named db.dbml (tried another on named test.dbml) and when I try this: public dbDataContext db = new dbDataContext(); I get: The type or namespace name 'dbDataContext' could not be found ... Am...

Can this be refactored into nicey nice LINQ?

I have an IList of type Breadcrumb which is just a lightweight class that has NavigationTitle, NavigationUrl and IsCurrent properties. It is cached on the webserver. I have a method that builds out the current breadcrumb trail up until the first Breadcrumb that has IsCurrent set to true... using the code below. Its very ugly and definite...

How .NET 3.5 (lambdas, Linq) evolved

I remember reading a post about a year or so ago by Scott Hanselman (maybe by scott guthrie) about how Linq evolved. It remember it showing that anyonymous types led to lambda expressions which then led to Linq in some way. I can't seem to find it on google. Does anyone else remember this post? If so, can you please post it? ...

Querying DataColumnCollection with LINQ

I'm trying to perform a simple LINQ query on the Columns property of a DataTable: from c in myDataTable.Columns.AsQueryable() select c.ColumnName However, what I get is this: Could not find an implementation of the query pattern for source type 'System.Linq.IQueryable'. 'Select' not found. Consider explicitly specifying the t...

Getting a collection of index values using a LINQ query

Is there a better way to do this? string[] s = {"zero", "one", "two", "three", "four", "five"}; var x = s .Select((a,i) => new {Value = a, Index = i}) .Where(b => b.Value.StartsWith("t")) .Select(c => c.Index); i.e. I'm looking for a more efficient or more elegant way to get the positions of the items matching the criteria. ...

LINQ to SQL -

I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: Message: Specified cast is not valid. Type: System.InvalidCastException Source: System.Data.Linq TargetSite: Boolean TryCreateKeyFrom...

help with Anonymous Types in a signature

Hi all, I am trying to get the signature on the method below to work. As this is an Anonymous Type I have some trouble, any help would be great. When I looked at sortedGameList.ToList() in a QuickWatch window I get the signature "System.Collections.Generic.List<<>f__AnonymousType0>>" Many Thanks Donald public List<IGrouping<Dat...

Algorithm/pattern for selecting sub-collections using LINQ and C#

I have a C# collection of strings. Each string is a sentence that can appear on a page. I also have a collection of page breaks which is a collection of int's. representing the index where the collection of strings are split to a new page. Example: Each 10 items in the string collection is a page so the collection of page breaks would b...

StackOverflowException caused by a linq query

edit #2: Question solved halfways. Look below As a follow-up question, does anyone know of a non-intrusive way to solve what i'm trying to do below (namely, linking objects to each other without triggering infinite loops)? I try to create a asp.net-mvc web application, and get a StackOverFlowException. A controller triggers the follo...

Linq to Sql - Loading Child Entities Without Using DataLoadOptions?

Is it possible to load child entities in a single query without using DataLoadOptions? I am using one data context per request in an asp.net web application and trying to get around the linq to sql limitation of not being able to change dataloadoptions once a query has been executed. Thanks. ...