linq-to-sql

Conversion failed when converting datetime from character string. Linq To SQL & OpenXML

Hi I been following this tutorial on how to do a linq to sql batch insert. http://www.codeproject.com/KB/linq/BulkOperations_LinqToSQL.aspx However I have a datetime field in my database and I keep getting this error. System.Data.SqlClient.SqlException was unhandled Message="Conversion failed when converting datetime from ...

Would this rollback/stop all records from inserting?

Hi I been going through this tutorial http://www.codeproject.com/KB/linq/BulkOperations_LinqToSQL.aspx and them make a SP like this CREATE PROCEDURE [dbo].[spTEST_InsertXMLTEST_TEST](@UpdatedProdData nText) AS DECLARE @hDoc int exec sp_xml_preparedocument @hDoc OUTPUT,@UpdatedProdData INSERT INTO TBL_TEST_TEST(NAME) SELECT...

How do I populate my VS2008 Data Sources window with a LINQ query table?

I´m (professionally) creating a SQL Server database client by using Visual Studio 2008, C# -> Windows Form(s). And I´m using all the built in stuff, provided by my friend VS Studio, dragging and dropping, creating SQL query tables in DataSet.xsd, and so on... I like that. But! I would like to try out LINQ, as I would like to have somet...

Most efficient way to update with LINQ to SQL

Can I update my employee record as given in the function below or do I have to make a query of the employee collection first and then update the data? public int updateEmployee(App3_EMPLOYEE employee) { DBContextDataContext db = new DBContextDataContext(); db.App3_EMPLOYEEs.Attach(employee); db.SubmitChanges(); ...

Linq-To-Sql equivalent for this sql query...

I thus far used concatenated Id string like 1,2,3 and updated in my table using this query... if exists( select ClientId from Clients where ClientId IN (SELECT i.items FROM dbo.Splitfn(@Id,',') AS i)) begin update Clients set IsDeleted=1 where ClientId IN (SELECT i.items FROM dbo.Splitfn(@Id,',') AS i) select 'delete...

nested join linq-to-sql queries

var result = ( from contact in db.Contacts where contact.ContactID == id join referContactID in db.ContactRefferedBies on contact.ContactID equals referContactID.ContactID join referContactName in db.Contacts on contact.ContactID equals referContactID.ContactID orderby cont...

Linq to SQL - Inserting entities with relations

Consider the following tables (screenshot of dbml file editor in Visual Studio): The IngredientsRecipesRelation table is a many-to-many table, linking n ingredients to a single recipe. How would you insert the following recipe...: Recipe { Name = "Dough" } With the following ingredients...: Ingredient { Name = "water", Unit = "cu...

How can I avoid setting some columns if others haven't changed, when working with Linq To SQL?

In LINQ to SQL, I want to avoid setting some columns if others haven't changed? Say I have dim row = (From c in dataContext.Customers Where c.Id = 1234 Select c).Single() row.Name = "Example" ' line 3 dataContext.SubmitChanges() ' line 4 Great, so LINQ to SQL fetches a row, sets the name to "Example" in memory, and generates an upda...

Returning IEnumerable<T> vs IQueryable<T>

what is the difference between returning iqueryable vs ienumerable. IQueryable<Customer> custs = from c in db.Customers where c.City == "<City>" select c; IEnumerable<Customer> custs = from c in db.Customers where c.City == "<City>" select c; Will both be deferred execution? When should one be preferred over the other? ...

How to handle Foreign Keys with Entity Framework

I have two entities. Groups. Pools. A Group can create many pools. So I setup my Pool table to have a GroupID foreign key. My code: using (entity _db = new entity()) { Pool p = new Pool(); p.Name = "test"; p.Group.ID = "5"; _db.AddToPool(p); } This doesn't work. I get a null reference exception on p.Group...

Linq to SQl Stored Procedure Problem( it can't figure out the return type)

Hi I have this SP USE [Test] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[UsersInsert](@UpdatedProdData XML) AS INSERT INTO dbo.UserTable(UserId,UserName,LicenseId,Password,PasswordSalt,Email,IsApproved,IsLockedOut,CreateDate, LastLoginDate,LastLockOutDate,FailedPasswordAttempts,RoleId) ...

One-to-many relationship related to many tables

I have a scenario where: there are two (or more) tables that represent independent items. lets say Users and Companies Both of these tables need addresses stored. Each one can have one or more address In a normal 1 to many scenario Addresses table woudl just have a UserId or a CompanyId creating a normal 1 to many relationship. In ...

Which isolation level should I use for the following insert-if-not-present transaction?

I've written a linq-to-sql program that essentially performs an ETL task, and I've noticed many places where parallelization will improve its performance. However, I'm concerned about preventing uniquness constraint violations when two threads perform the following task (psuedo code). Record CreateRecord(string recordText) { using ...

How to order the items in a nested LINQ-provided collection

I've got a (SQL Server) database table called Category. And another database table called SubCategory. SubCategory has a foreign key relationship to Category. Because of this, thanks to LINQ, each Cateogory has a property called SubCategories and LINQ is nice enough to return all the SubCategories associated with my Category when I grab...

How to do a batch update?

Hi I am wondering is there a way to do batch updating? I am using ms sql server 2005. I saw away with the sqlDataAdaptor but it seems like you have to first the select statement with it, then fill some dataset and make changes to dataset. Now I am using linq to sql to do the select so I want to try to keep it that way. However it is t...

Can I use TransactionScope to do distributed transaction?

Hi I have a MVC app that uses Linq2Sql to access a SQL DB. But I want create a distributed transaction to update another DB on different local server. I want to update both in a transaction. Can I just wrap logic in TransactionScope class??? Malcolm ...

How can I improve the performance of LinqToSql queries that use EntitySet properties?

I'm using LinqToSql to query a small, simple SQL Server CE database. I've noticed that any operations involving sub-properties are disappointingly slow. For example, if I have a Customer table that is referenced by an Order table, LinqToSql will automatically create an EntitySet<Order> property. This is a nice convenience, allowing me ...

asp.net mvc diff between DeleteAllOnSubmit and deleteonSubmit

What is the real difference b/w DeleteAllOnSubmit and deleteonSubmit and which one is more appropiate to use? ...

Using LINQ to fetch result from nested SQL queries

This is my first question and first day in Linq so bit difficult day for me to understand. I want to fetch some records from database i.e. select * from tblDepartment where department_id in ( select department_id from tblMap where Guest_Id = @GuestId ) I have taken two DataTable. i.e. tblDepartment, tblMap Now I want to fe...

LINQ to SQL: filter nested objects with soft deletes

Hello everyone, I'm using soft deleting in my database (IsDeleted field). I'm actively using LoadWith and AssociateWith methods to retrieve and filter nested records. The thing is AssociateWith only works with properties that represents a one-to-many relationship. DataLoadOptions loadOptions = new DataLoadOptions(); loadOption.LoadWi...