linq-to-sql

LINQ 2 SQL error :The null value cannot be assigned to a member with type System.Byte which is a non-nullable value type

I m trying to write a LINQ 2 SQL query wuth left our joins.But when executing i am getting the below exception The null value cannot be assigned to a member with type System.Byte which is a non-nullable value type My LINQ 2 SQL Query is here Dim items = (From i In oRecelDB.IV00200s _ Group Join c In oRecelDB.MDS_CON...

Can Linq to SQL/Linq to Entities generate a MERGE statement?

Looking for a combined INSERT/UPDATE/DELETE statement, MERGE is exactly what I need, but I can't seem to find if LINQ/SQL supports it (from http://www.sqlbook.com/SQL-Server/SQL-MERGE-35.aspx) -- Merge order items into OrderItems table MERGE INTO OrderItem As oi USING @UpdatedItems ui ON (oi.OrderID = ui.OrderID AND oi.ProductID = ui.Pr...

How do I execute LINQ queries against a database with varying schema?

I need to execute read-only queries against a database that I don't control. My top choice would be Linq to SQL, however, the column names differ slightly between our Dev, QA, and Production environments. For example, take a FolderName column. We might have: Dev: u34_FolderName QA: u74_FolderName PROD: u56_FolderName I want to d...

T-SQL: Double-cocked Trigger, Polling or a .NET Async Thread?

So i bet i got you curious with that title. =) Here's the scenario - simplified for the cause. Website: ASP.NET 4 Web Forms. Database: SQL Server 2008. DAL: LINQ-SQL. In the DB, we have two tables: Foo and Bar. Relationship is 1-1, and Bar has a foreign key constraint to Foo. In other words, you need to create Foo first, then use t...

How do you pass an array of integers to a stored procedure or function using linq to sql

I was just asked how to go about passing an array of integers into a stored procedure or function using LINQ to SQL. As I have never done this and don't see anything on Google I figured I would ask here. Thanks! ...

Linq2Sql: How do manage large resultsets?

Let say I have a query with a very large resultset (+100.000 rows) and I need to loop through the and perform an update: var ds = context.Where(/* query */).Select(e => new { /* fields */ } ); foreach(var d in ds) { //perform update } I'm fine with this process taking long time to execute but I have limited amount of memory on my ser...

LINQ-to-SQL performance issue for mass inserts.

Hi, I have identified a problem within my application; basically, one sub-routine prepares (lots) of data that is later on inserted into my local database via a LINQ-to-SQL data context. However, even a relatively modest amount of new data (100,000-ish) takes a tremendous amount of time to be saved into the database when SubmitChanges()...

How to choose that which ORM would be feasible for or Application? e.g if we are using Linq then why not hibernate

How to choose that which ORM would be feasible for a web Application? e.g if we are using Linq then why not nhibernate? and Which one is better and why ...

Need Linq Query Help

I have the following simple Linq query: (from container in Container join containerType in ContainerType on container.ContainerType equals containerType where containerType.ContainerTypeID == 2 select container).Max (row => row.SerialNumber) As is, this query works fine. The problem is that SerialNumber, in the DB, is an nvarchar type...

Record-level Security in LINQ-to-SQL

I'm working on a record-level security system for a LINQ-to-SQL app. I currently have a wrapper around the DataContext's GetTable method that joins T to a user cross-reference table. T is any class that implements my ISecurable interface: public interface ISecurable { bool CanRead { get; set; } bool CanUpdate { get; set; } ...

Help with OR logic in Linq lambda query

I'm a bit stuck on the following linq query. I'm trying to find all orders which have a state other than "Completed", or which have been completed within the last month. _ordersRepository.GetAllByFilter( o => o.OrderStatus .OrderByDescending(os => os.StatusUpdate.Date) .First() // so at this point I ha...

LINQ to SQL - DuplicateKeyException during update

The code listed below attempts to update a row in the database, but throws an exception instead: System.Data.Linq.DuplicateKeyException: Cannot add an entity with a key that is already in use Most examples I've seen query the database to obtain an instance of an entity, modify some of the instance's properties, and then update ...

Question about data access with LINQ and Stored Procs (NOT asking which is better!)

First, I am NOT trying to spur yet another debate about LINQ vs. stored procedures. Assume for this question (for right or wrong) that I'm going to use SQL server stored procedures and will access those stored procedures via LINQ. I am using stored procedures (again, for right or wrong) because I want to enforce security at the stored ...

LINQ 2 SQL : Loading more than one result sets to a variable when executing a stored procedure from LIN2 SQL.

In LINQ 2 SQL,I am executing a stored procedure like datacontext.StoredProcedureName(parameter1,paramter2) My sotored procedure is returning 2 different resultsets.How can i catch it and parse over it to grab the values from it VB.NET am working with ...

Join queries and when it's too much...

I find that I am using a lot of join queries, especially to get statistics about user operations from my database. Queries like this are not uncommon: from io in db._Owners where io.tenantId == tenantId join i in db._Instances on io.instanceId equals i.instanceId join m in db._Machines on i.machineId equals m.machineId selec...

How often to call DataContext.SubmitChanges() for a large number of inserts?

How many InsertOnSubmit should I call before calling SubmitChanges? I'm adding data from a web service that can return tens of thousands of records one record at a time. The wrapper class around the web service exposes the records a an IEnumberable collection to hide an elaborate chunking mechanism. Are there guidelines on how many inse...

Linq to SQL Where In Clause Causes Object not set to instance of object

I have two tables, subscriptions and topics. Each subscription is related to a specific TopicID (PK for topics table). The first query works fine and retrieves the topicID's of all videos that were uploaded today. The problem occurs when I try and then use the results of query1 as a where-in clause for query 2. I keep receiving object ...

LINQ to SQL, Delete row from Table using a DataGridView in C#

Hi All, I have a DataGridView that is bound to a table. I need to be able to rightclick on that DataGridView and it needs to select the right clicked row and open the context menu and when i click delete i need it to delete that row from the table. The contextmenu is all made etc i just need to know how i can get that delete to work!!! ...

How to call a store procedure which returns a dynamic XML from C# using MVC?

Hello there, I'm new using C# and Linq, I hope you can give me hand on this. First, I have a SP on my DB basically called like this: ALTER PROCEDURE [dbo].[getUsersThemesXML] @xmlUsers XML OUTPUT AS...etc... I'm working with MVC so, from my controller I have to call the SP with the empty XML as parameter and get it on the application ...

Is there a LINQ equivalent to SQL's "0 rows affected"?

I have a simple LINQ to SQL delete statement and would like to know if there is a way to find out the number of records deleted? Sample code would be appreciated ...