linq-to-sql

How to compare List<String> to DB Table using LINQ

I have a list<> of phone numbers and I am trying to join that with the corresponding records in the db table and get an order number and a customer ID. Also the list has the whole number as one string and the DB has it broken to area code, prefix, number each as separate fields. I am fairly new to LINQ, so this is a beyond what I curren...

Elegant solution - delete and re-add related child list as a batch with Linq-To-SQL

I've got a table called ItemAttributes that is going to have many records for any given parent item record. The user interface allows the user to add/remove ItemAttributes in batch mode and click save one time. So in the case of update I need to do one of two things. Delete all prior ItemAttributes and add all resulting items the us...

Linq to Sql - Converting a join and sum from sql to linq....

I have crawled over several of the various questions on Linq-to-SQL dealing with joins, counts, sums and etc.. But I am just having a difficult time grasping how to do the following simple SQL Statement... SELECT tblTechItems.ItemName, SUM(tblTechInventory.EntityTypeUID) AS TotalOfItemByType FROM tblTechInventory...

Annoying SQL exception, probably due to some code done wrong

I started working on this "already started" project, and I'm having a really annoying error when trying to execute some interactions with SQL Server 2008: The server failed to resume the transaction. Desc.: One of these errors I get in this specific method call: The aspx.cs Call: busProcesso openProcess = new busProcesso(pProc...

LINQ Insert Into Database resulted in duplicates

I have a linq query running in a WCF Web Service that looks for a match and if one is not found then it creates one. my code looks like //ReadCommitted transaction using (var ts = CreateTransactionScope(TransactionScopeOption.RequiresNew)) { Contract contract = db.Contracts.SingleOrDefault(x => x.txtBlah == str); if (c...

Linq To SQL migration to Entity framework 4

We are planning to migrate to .net 3.5 and evaluating Linq To SQL and Entity framework. Considering what people are saying every where on internet that EF 1.0 is buggy, complex, has suboptimal designer support etc, if we pick Linq to SQL - do you think we will be able to migrate it to EF 4 when the time comes? The question arises becaus...

LINQ to SQL: Many to many with Multiple primary keys?

Ok this is something a bit simple but as I'm new to Linq and to SQL overall I guess I need a little help. Most tutorials assumed some sql knowledge and therefor weren't as helpful and also hard to search as I do not know this join name ( Inner left? ). Situation: TableParent with 2 primaryKeys, ParentKey1 and ParentKey2 TableChild with...

Delete object and its many-to-many relation

I am trying to delete an object that sometimes has a many-to-many relation. The code I use now is: db.DeleteObject(registeredDevice); db.SaveChanges(); This ofcourse just removes the registeredDevice. But usually this device has a many-to-many relation to a project in the database. When trying to delete the device in that scenario it...

How to update data model class after manually changing .dbml file

Hello. Does anyone know how could I get the data model class updated after I make some custom changes in the .dbml file. I tried to manually mark some fields nullable in the .dbml, but changes are not visible in the code, no matter how many times I rebuild. I even tried to edit .dbml(xml) in an external tool, and then save, but no use....

ASP.NET 4 SQL Methods?

Hi, Currently working on an ASP.NET web app and am starting to realise i'm writing the same Boiler Plate Code Over and Over Again.. i.e. SqlDataReader myReader = null; SqlCommand SQLcmd = new SqlCommand(); SqlConnection SQLConn = new SqlConnection(); String SQLStatement = "Select this 'nd That"; ...

Setting IsPrimaryKey=true on column in table with no primary key

Hi, I'm writing a quick app using LINQ to SQL to populate a db with some test data and had a problem because one of the tables had no primary key as described by this bloke Can't Update because table has no primary key. Taking the top answer I added the IsPrimaryKey attribute to an appropriate column and the app worked even though the...

encapsulating logic in a linq to sql query via extension method.

Given two classes in your LINQ to SQL .dbml file with the following properies. Customer CustomerId FirstName LastName AddressId Address AddressId Street City State Zip You could construct a LINQ query such as the following. using(var db = new MyDataContext()) { results = db.Customers ....

How StandardChangeTracker class track a field's change?

In Linq if we change a entity's propety value,StandardChangeTracker class will catch the change,how it works? ...

How i use Contains for string in Linq to Sql to match only the beginning of a word

I can use linq to sql to match a part of a string with From C In DB.City Where C.Name.Contains(Query) What i need to do for it to match only beginning of words? (Behave like full text index) ...

Linq to SQL and Intersect

Folks, I need to use Intersect on a LINQ to SQL query. However, I get an exception basically stating that I can't. The code compiles fine, but LINQ to SQL gets angry. Is there any way to replicate Intersect with LINQ to SQL? Thanks in advance. ...

Fetch n bind data from StoredProcedure with Join, LINQ then Split. using IMultipleResults,Linq2SQL

Hi Everybody I Have one application in it i am using stored procedure and LINQ my procedure is like myProc select col1, Col2, Col3 from Tab1 inner join Tab2 on col1=ColA join tab3 on Col1=ColD Select cola, Colb, Colc from Taba inner join Tabb on cola=ColX join tabc on Cola=ColY Select colP, ColQ, ColR from TabP inner join TabQ on...

SQLMetal generates code from stored procedures incorrectly.

sqlmetal wrongly generates code for my sproc as ISingleResult. I need multiple results! Check this out. SqlMetal actually generates ISingleResult for a sproc like this: CREATE PROCEDURE GetDetailReportData AS BEGIN select * from Log END How do you get sqlmetal to generate with multiple results for a sproc? Does anyone ever use sproc...

How to tell if a LINQ to SQL query is translated to a SQL statement or not?

We use LINQ to SQL extensively, and one of the biggest performance pitfalls we've run into is situations where a query can't be converted to SQL, and so an entire database table gets loaded into memory and the query performed by .NET. For example, this query Dim Foo = (From c in Db.Contacts Select c Where c.ContactID=MyContactID) tran...

LINQ to SQL mystery: Why does query include all fields in some cases but not others?

This LINQ to SQL query From g In Db.Context.Current.Groups Select g.GroupID generates this SQL: SELECT [t0].[GroupID] FROM [dbo].[Groups] AS [t0] But this query From g In Db.Context.Current.Groups Select g.GroupID, g.MemberCount generates this SQL: SELECT [t0].[GroupID], [t0].[Title], [t0].[Description], ... -- 24 more f...

Linq to SQL - Parameters being assigned incorrectly/duplicates

I started with this question: (how-to-compare-liststring-to-db-table-using-linq). Using the solution offered there, it worked for my test with only 5 items in my list. I'm having an issue with this now. I'm getting a SQL error saying "error near 0". After using a LINQ to SQL visualizer, the problem is when Visual Studio is assigning t...