linq-to-sql

LINQ, Select where Title Matches, Else if Object is Null

I have a basic tag searching system setup, each tag has a field for an ID for a category. Some tags will have no category. So in my methods, I just pass a string through to define the category to get in a list. public IQueryable<Tag> List(string category) { //... } I want to return tags that have no category if nothing is passed th...

Will linqtosql take care if many threads are accessing the same table of the database at the same time?

I am working on a asp.net mvc application. I have a situation where I have to make many threads which are going to access the database using linqtosql. My question is, will it be fine to leave every thing on linqtosql to maintain the synchronization, because the threads will be accessing the database at the same time. Or I have to write ...

How to handle transactions in dotnet world?

Hi, we are using linq-to-sql in a desktop project? How should we handle transactions? What about using transaction scope? ...

vs2010 Linq to SQL -- adding an entity from my DBML

I think I may be going crazy here... Anyways, I have a DBML with a table 'User' in it. Pretty simple stuff -- From within a class, I have the following: BusinessDataContext businessDataContext = new BusinessDataContext(); var user = new User(); user.FirstName = FirstName; user.LastName = LastName; user.MiddleInitial = MiddleInitial; u...

Is passing a L2S DataContext into a ViewModel constructor clean MVVM?

In my main Window1.xaml.cs, I build an ObservableCollection of ViewModels like this by instantiating with a LINQ-to-SQL model object: using (var db = Datasource.GetContext()) { var customers = from c in db.Customers select c; foreach (var customer in customers) { CustomerCollection.Add(new Custom...

Model for ASP.NET MVC

Hi I just started with ASP.NET MVC 1.0. I've read through some tutorials but I don't have any good ideas on how to build my model. I've been experimenting with LINQ to SQL. Can't say I like it that much, but I'll give it a try. I prefer using SQL Stored Procedures, but it doesn't seem to work very good together with the optional parame...

Fetch from foreign key tables with LINQ and LINQ to SQL

Hi I have an database table called MenuItem (MenuItemID, ParentMenuItemID, MenuItemName). I want to use this to populate a Menu control (probably the .NET Menu control). Each MenuItem has a parent. If there is no parent, it is a top level menu item. I have made a LINQ to SQL class mapped to the MenuItem table. As my table has a foreign...

How to retrieve multiple rows from a stored procedure with Linq to SQL?

I've recently started to work with Linq to SQL and wondered how to get multiple rows as a result of executing a stored procedure,here's a simple sp i want to work with: CREATE PROCEDURE gsp_ftsmultiple @SearchKey varchar(100) AS BEGIN SET NOCOUNT ON; SELECT Label, theContent FROM FtsTest WHERE FREETEXT( theContent, @Se...

Best practice for my solution

I have asked this question http://stackoverflow.com/questions/1900415/what-is-the-best-way-to-dynamic-load-connection-strings But maybe it's better to ask the question a little different. I have a CRM solution where I have different SQL databases for each company, but I would like to try to only have one IIS site, since the site is alw...

How to convert update/join SQL to Linq To SQL?

I would like to convert this t-sql to linq to sql. UPDATE Table1 SET CustomerName = 'john Doe' FROM Table1 JOIN Table2 ON Table1.TableID = Table2.TableID WHERE CustomerID = 4 ...

Custom orderby in linq to sql

Hi I've already searched the archives but can't find a solution that works for linq to sql. How do you create a custom orderby in linq to sql so that it generates SQL code like this ORDER BY CASE SEASON WHEN 'WINTER' THEN 1 WHEN 'SPRING' THEN 2 WHEN 'SUMMER' THEN 3 WHEN 'AUTUMN' THEN 4 END Note that custom comparators dont s...

Handling a Linq-To-Sql mapping to a table colum with a default value/binding

I have a Linq-To-SQL mapping to a column in a SQL table. This column is type DateTime with default mapping / binding of getdate(). The problem is that Linq-To-SQL tries to insert 12/1/0001 12:00 AM instead of letting SQL do its thing and insert getdate(). Is there a way around this? Additionally, if the column is allowed to be null, ...

How to insert/update/delete multiple objects with a single query in Linq to Sql

Linq to Sql handles every insert/delete/update operation on an object with separate query. Is there a way to unite multiple operations in single query? I know this is not possible with the default behavior of the framework. I'm looking for an extension method or workaround. I want to use the queries generated by Linq to Sql, not my own...

Linq Compiled Queries and int[] as parameter

Hello , i'm using the following Linq to Sql compiled query. private static Func<MyDataContext, int[], int> MainSearchQuery = CompiledQuery.Compile((MyDataContext db, int[] online ) => (from u in db.Users where online.Contains(u.username) select u)); I know it is not possible to use sequence input pa...

LINQ to SQL -- Same User Object, different data context.

I have a user object called UserSystem, which is created by a static factory class that returns User Systems. Because the factory class only exists to create this object once, then disposes, is it possible to associate my persisted UserSystem object with another instance of my database context that I create at a later point? I would li...

Is it safe to use compiled linq queries in asp.net applications

I see a lot of posts of people using compiled Linq to Sql queries for high-demand asp.net applications. I've done some performance tests and in many cases compiled queries are better than the ordinary ones. What bothers me is that when using compiled queries the query is preserved in a static variable. In asp.net in many cases it is not ...

LinQ updating duplicate records into Detail table

Hello Experts, I have two tables emp and empDetail. Using linQ I am inserting records from my VB.net Windows Service every night. Before inserting I am checking if the record already exists in emp table. If record doesn't exist I am inserting it else I am skipping it. For some reason the service ran twice last night and I noticed that,...

Linq : Why this approach don't seem to work? What should be the standard approach?

Why this approach don't seem to work? What should be the standard approach? [Database(Name = "Test")] [Table(Name = "Order")] public class Order { [Column(Name = "ID", IsPrimaryKey = true)] public int ID { get; set; } [Column(Name = "OrderDate")] public DateTime OrderDate { get; set; } public static Order Get(int ...

Linq to SQL & Logical partitioning (DAL, BLL)

We're going to be rebuilding one of our sites in .Net. I've read many articles and really like the idea of separating our project into a data access layer (DAL), Business logic layer (BLL), and presentation layer (we're coming from classic ASP so this is a massive step for us). I also really like Linq to SQL. Since Linq to SQL is aimed...

Fill a Recursive Data Structure from a Self-Referential Database Table

This question refers to http://www.matthidinger.com/archive/2009/02/08/asp.net-mvc-recursive-treeview-helper.aspx Let's say I have a table that looks like this: And I have a recursive data structure that looks like this: public class TreeNode { public TreeNode(){} public string NodeId { get; set; } public string ParentId...