linq-to-sql

attachment property in several models

Hi! I am using ASP.NET MVC + LinqToSQL. There is attachment model in my application. I need <IEnumerate>Attachment Attachments in several models. I don't wasn't to create different attachment models for different parent classes. Is there simple way to do it? ...

Import XML to SQL using C#

I know its kind non sportiness asking for this kind of help, But I am relay stacked on this for while, Temporally I am reading two C# books and working everyday over 9 hours. Okay here is my problem I have WIN C# application that I almost done. In SQL i got a three tables look like this: CREATE TABLE [dbo].[Racuni]( [BROJ] [varchar](1...

Any big benefits of Linq to SQL/Entities if database allows stored procedures only?

Linq to SQL and Linq to Entities depend on creating dynamic SQL to do a lot of their work, specially when you have classes represent database tables in some fashion. However if the database(s) does not allow ad hoc SQL queries and everything has to go through stored procedures, I don't see the big value of using L2Q or L2E if the develop...

c#: How to pass linq-objects around

When showing my main window, I make a list of objects from linq-to-sql: using (var context = new Data.TVShowDataContext()) { Shows = new ObservableCollection<Data.Show>(context.Shows); listShows.ItemsSource = Shows; } Now, when I doubleclick an item in my list, I want to use the selected object in a new usercontrol: Sho...

How do you control the "SET" statements emitted by Linq to SQL

Hi - Is there any way to control the "SET" statements that Linq to SQL emits? I see these SET options coming from Linq to SQL in the SQL profiler and it turns out that "set arithabort off" is causing one of our procs to take 45 seconds as opposed to < 1 second. -- network protocol: TCP/IP set quoted_identifier on set arithabort off se...

How can I pass a char null in a Stored Procedure method in C# 3.0?

Hi everyone! I'm trying to make this SP run: myDataContext.InsertEvent(codEvent, dateOfEvent, statusOfEvent); codEvent is an int; dateOfEvent is a DateTime; statusOfEvent is a char. The problem is Visual Studio is throwing an error if I pass a statusOfEvent null. And, my SP accpts nullable char just like my table. I've tried to do ...

Why am I getting an InvalidOperationException with this Linq to Sql method?

Hi all. When Executing the following linq to sql statement: var stuff = from l in _db.SqlLinks select new { Link = l, Rating = (from v in l.SqlLinkVotes where v.Tag == tagId ...

ASP.NET MVC And LINQ General Questions

I've asked a few questions on this topic before. Before we're able to implement either MVC or LINQ at work we need to resolve a few issues. Multiple Record Sets in ASP.NET MVC The only examples of MVC in use only have a single result set returned. When using stored procedures multiple record sets can be retrieved, and the whole reaso...

LinqToSql stored procedures always makes the paramters nullable. Why?

Hi folks, whenever i drag-n-drop a stored procedure onto my Context canvas, the parameters/arguments for the stored procedure are all nullable. Why is this? Is it because of how i've declared my parameters inside the stored procudure itself? Besides manually creating my stored procedure methods in the Context partial class (or drag-n-d...

Why is LINQ to SQL inserting duplicates into my table?

I have a web service that retrieves reviews from my database and if not enough reviews are returned, it goes to a secondary source and gets them there and caches them in my database. I have recently noticed that it has been creating duplicates in my database despite me having primary keys to prevent it. I was thinking that maybe when I m...

Is it possible to gets sql connection leaks using LINQ?

I belived it was not possible to get sql connection leaks when using LINQ, but perfmon tracing of NumberOfReclaimedConnections shows a high number and on high load we sometimes get exceptions like "Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connec...

LINQ To SQL Paging

I've been using .Skip() and .Take() extension methods with LINQ To SQL for a while now with no problems, but in all the situations I've used them it has always been for a single table - such as: database.Users.Select(c => c).Skip(10).Take(10); My problem is that I am now projecting a set of results from multiple tables and I want to p...

Checking for time range overlap, the watchman problem [SQL]

I am running into a road block on a larger problem. As part of a large query I need to solve a "night watchman" problem. I have a table with schedule shifts as such: ID | Start | End 1 | 2009-1-1 06:00 | 2009-1-1 14:00 2 | 2009-1-1 10:00 | 2009-1-1 18:00 3 | 2009-2-1 20:00 | 2009-2-2 04:00 4 | 2009-2-2 06:00 | 2009-2-2 14:...

Is it possible to auto-generate my Linq2Sql DBML via a script?

I use Linq2Sql and am tired of recreating the dbml everytime the database changes. Is it possible to script the creation of my model given that I want ALL tables and ALL procs? Ideally it would be part of the build process or a custom tool. A simple "refresh from schema" button would be fine too, but from all I can tell, there is no s...

How to dynamically add OR operator to WHERE clause in LINQ

I have a variable size array of strings, and I am trying to programatically loop through the array and match all the rows in a table where the column "Tags" contains at least one of the strings in the array. Here is some pseudo code: IQueryable<Songs> allSongMatches = musicDb.Songs; // all rows in the table I can easily query this ta...

Need advice on selecting a data access method

I am in the early stages of planning a conversion of a large classic ASP database application to ASP.Net and I'm having trouble picking out which data access method to use. I have played around with Linq To SQL, Dynamic Data, strongly typed datasets, Enterprise Library (Data Access Application Blocks), and a tiny bit with Entity Framewo...

How do you use Linq to connect tables in different databases?

I'm a bit of a Linq newbie, and I couldn't find any documentation to help me with what seems to be a pretty trivial problem - so your help will be much appreciated! I have a table Table1 in database DB1, which has a "pseudo" foreign key Table2ID to table Table2 in database DB2, on the same server. "Pseudo", because obviously I can't ha...

LINQ to SQL and Join two tables with OR clause

Let's say I have Plans and Documents Dim myPlans = _context.Plans.Where(predicate1) Dim myDocuments = _context.Documents.Where(predicate2) I have structured the where clause for each using PredicateBuilder. So, myPlans and myDocuments have a correct SQL statement. What I'd like to do is join these two tables into one linq statement. ...

Update SubmitChanges() - does not update.

With this code there is no change in my database. when the above code is run there is no longer a new entry created neither is an entry updated. public void UpdateCallback(callback cb_) { callback call = context.callbacks.Single(c => c.callbackID == cb_.callbackID); //call.callbackID = cb_.callbackID; ...

Why is LINQ to SQL entity association creating a new (duplicate) row when inserting a new record?

I am trying to insert a new entity using LINQ-to-SQL, and entity is associated with a User entity. The insert of the new entity is successful, but my existing User entity gets inserted as if it were a new User. The code looks something like the following: var someEntity = new Entity(); someEntity.User = this.User; dataContextInstance.So...