linq-to-sql

How to optimise LinqToSQL in c#

hi, i am attempting to update approximately 150,000 records in a table in SQL 2005 using linq2sql. When it comes to xx.SubmitChanges() it is taking about 45 minutes. I am running sql as a local instance on a quad core pc. Does anyone know why this is taking so long? or is that normal? Code Sample: var y = db.x.Where(j => j.NumberOfOr...

How can i fill Anonymous type in list?

I try to write some codes about Generate list from Anonymous type via below codes : public static List<T> MakeList<T>(T itemOftype) { List<T> newList = new List<T>(); newList.Add(itemOftype); return newList; } But ERROR return me: A primary key field specified via the KeyFieldName property is not found in the underl...

LINQ subquery IN

Hi ! I'm a newbie with the IQueryable, lambda expressions, and LINQ in general. I would like to put a subquery in a where clause like this : Sample code : SELECT * FROM CLIENT c WHERE c.ETAT IN ( SELECT DDV_COLUMN_VAL FROM DATA_DICT_VAL WHERE TBI_TABLE_NAME = 'CLIENT' AND DD_COLUMN_NAME = 'STATUS' AND DDV_COLUMN_VAL_LANG_...

Two LINQ data contexts proving a problem

I'm getting this error when using LINQ2SQL: The query contains references to items defined on a different data context. Here's the code: var instances = (from i in context.List join j in context.CatsList on i.ListID equals j.ListID join c in context.Cats on j.CatID equals c.CatID ...

LINQtoSQL - How do I get my query to recongize which table I want?

Hello SO, I'm using LINQtoSQL to create cascading deletes IE: if Category is deleted then all the Products in that category are also deleted. I have a Products repository set up already (IProductsRepository) and now I'm working in my Category repository to add the business domain logic for the cascade. Products repository has this met...

(Linq to SQL) Why is my Concat failing?

What im trying to do is search thru multiple tables (that are kind of unrelated) and everytime it finds a match - create a new more generic "Results" Type for everytable - concat this result type set. The error i get is: All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their t...

.NET APP trouble writing group by and join clause with edmx

i have the following working query in mysql... select * from events e join performance_times pt on e.id = pt.event_id where pt.performance_date_only > '2010-08-10 00:00:00' group by pt.performance_date_only I am having issues getting the group by to work when using this with my edmx file in my mvc app. I have it working with the jo...

How do I retrieve items that are tagged with all the supplied tags in linq?

I seem to be having trouble with this. I have a Task table with an ID, and a Tag table, that has a tag field and a foreign key constraint to the task table. I want to be able to perform AND searches for tasks by tags. So for example, if I search for tasks with the tags "portability" and "testing", I don't want tasks that are tagged ...

WPF:How to Tell my DataLayer which DataContext to use ?

I have a solution where i have 3 WPF projects under it(Project UI-A, Project UI-B and Project named CommonLibrary(Data Layer).I have a user registration form in the Project UI-A where i will capture the User profile information.And in the CommonLibrary project i have a class called "UserCommon" which will have a method to save the data t...

Transactions in LINQ To SQL

I am using LINQ To SQL and calling stored procedures to insert the new rows. Does the code below demonstrate an appropriate set of steps? I want to insert (other fours) only if all four inserts are passed otherwise rollback all four inserts. public bool InsertNewInquiry(Inquiry inq) { using (var transaction = new TransactionSco...

Linq-to-SQL best practices: Deleted entities not really being deleted.

Being new to Linq-to-SQL, I ran into one of it's Gotchas today and I wanted to share my solution and then ask if there was something better. I'm setting up a staff allocation tool for my work. There are three basic class/tables: Employee, Project, Assignment. Importantly here, Assignment serves as a junction table between Employee and...

How Long to keep a LINQ-to-SQL DataContext Open?

I'm new to linq-to-sql (and sql for that matter), and I've started to gather evidence that maybe I'm not doing things the right way, so I wanted to see what you all have to say. In my staff allocation application I allow the user to create assignments between employees and projects. At the beginning of the application, I open up a linq...

LINQ to SQL - There is already an open data reader associated with this command whic must be closed first.

Hi, Recently i implemented Linq to SQL in a static class in my ASP.Net project which is a utility class to get some information on site load. when i used the static linqtosql datacontext i got the above error only in the live environment but never got that issue on UAT, or QA sites. ( this means this issue only happens when there is a m...

AutoMapper -- how to manipulate all values of a given type during mapping?

Quick question regarding Automapper. I'm mapping data from an incoming web service, where datetimes fields are not null, but sometimes have the value of DateTime.MinValue as a work-around (I don't own this service so I'm at their mercy I'm afraid). I'm mapping from those objects to Linq To Sql objects created off of a db model I create...

Are there any shortcuts in L2S Projection with lots of mismatched fields?

Help! My fingers are falling off from typing so much. I have a lot of objects that have sane names to them. The Database names are not so sane, and i'm stuck defining my property names in all my projections. For example: from f in foo select new MyClass() {MyID = f.ID, MyName = f.f, MyTime = f.t} Etc.. now, multiply this by hundr...

Logic for displaying infinite category tree in nested <ul>s from Self Join Table

Hi everybody! Please help me solve my big problem. in my on-line shopping project i created a dynamic Category List (with Infinite Level Depth) Implemented in a Single Table in DB with Self join. the schema is like below: Update I want to use a JQuery plugin to make a Multi Level Menu bar. this plugin uses <ul> and <li> elements so I sh...

Dealing with various epochs in time manipulation queries.

Much has been written about the difference between SQL Server, Unix, and Microsoft OLE Automation Time epochs. SQL Server treats 1/1/1900 as the epoch, while OLE treated it as 12/30/1899 for various reasons. I've read all the history, and it's fascinating, but doesn't help me solve my problem. I find myself writing a lot of queries on...

Function evaluation timed out

Hi, I am using linq to sql in a Silverlight application and I keep getting this debug error.. http://www.freeimagehosting.net/uploads/bf4055b4ee.jpg This code runs when the application is started up without problems. When I call it the second time, I only get a few of the results. When I add a breakpoint to the WCF service I get the fo...

Data Access Layer - LINQ-To-SQL and generics. Can I optimize this?

Hi, We are working on improving our DAL which is written in LINQ that talks to the MS SQL database. Our goal is to achieve good re-usability with as little code as possible. LINQ generated files are making a use of generics and reflection to map LINQ generated classes to the SQL objects (tables and views in our case). Please see the e...

LinQ to SQL query database and assign to current instance (this)

I have a public method called LoadContact() in the Contact class. I want to load the contact data using Linq and assign the values to 'this' instance. So far I have ..... var contact = (from cont in db.Contacts from note in db.Contacts_Notes.Where(n => n.ContactID == cont.ContactID).DefaultIfEmpty() where cont.AccountID == thi...