linq-to-sql

Linq2Sql: Using IQueryable in select

This is probably quite trivial but.... I have a quite complicated linq query that I have put in a IQueryable function that I'd like to reuse throughout the project. But when I use this in a select I get "System.Linq.IQueryable`1[LINQPad.User.Orders] Foo(System.Guid) doesn't have a translation to SQL": (very simplified to show what I've a...

DeleteOnNull attribute always removed from designer file

I have a number of associations within my LinqToSql designer file that I have had to add the attribute DeleteOnNull to. However if I change anything through the GUI then the designer file is re-created and I lose my DeleteOnNull attributes. Is there anyway I can stop this happening? ...

LINQ2SQL DataContext BindingSource question

Hi. I am almost a total novice to Linq2Sql notions except for few How Do I series videos :) I have some classes in my DataContext. GartPTSDataContext GetDataContext() { SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(Settings.Default.DBConnection); sb.Password = "sql"; GartPTSDataContext dtx = ne...

Which is the another option rather than LINQ to SQL in ASP.NET MVC?

HI, I am currently using the ASP.NET MVC pattern for my small application. I am using LINQ to SQL to manipulate with objects of model. I am using lambda and queries to manipulate. But as i found lot of limitations with LINQ to SQL concept I am planning to remove. so which is the best option rather than LINQ to SQL for manipulation with d...

linq to sql in a multithreaded environment ( and WCF)

Hi All, we have designed a multi threaded server that use linq to sql at each of its threads. the test are not look so good... from reviewing our code, a big question has be raised: does linq to sql supports such environments at all? if yes, we assume that we should create a dedicated DataContext object for each thread? if yes, what is...

Converting a SQL query with group by into LINQ query.

I'm stuggling to replicate a SQL query into LINQ. Can any one help? SQL: SELECT tblInvoice.lngID AS InvoiceID, tblInvoice.dtTimeStamp AS InvoiceDate, tblInvoice.strReference, tblInvoice.fltTotalValue, max(Project.ProjectID) AS ProjectID, max(Project.Projec...

Linq to Sql with Stored Procedure

I am trying to use stored procedure in dbml, but I get below error. The Stored procedure has multiple join tables, but it returns a row. public static List<SP_EMP_MASTER_DETAILResult> GetEmployeeDetail(string userName, string userLocation) { var query = (from q in db.SP_EMP_MASTER_DETAIL(userLocation, userName) sele...

Pluralize English words Like LINQ to SQL Does

Possible Duplicate: Pluralize - Singularize The C# 4.0 (maybe older versions, but I've only tested with 4.0) Linq-to-SQL generator will pluralize your table names; even tough plurals like Territory. It knows that Territories is the plural. Is there anyway to access this pluralization function? ...

Convert SQL query to LINQ

Hello everybody, I have a beginners LINQ2SQL question. I have this huge (but not complex) SQL statement: SELECT Artikel.ArtikelID, Artikel.CategorieID, Artikel.ImageFile, Artikel.RetailPrijs, ISNULL(ShopArtikel.VerkoopsPrijs, Artikel.VerkoopsPrijs) AS VerkoopsPrijs, Artikel.ArtikelCode, A...

SQLMetal Multiple Foreign Keys Pointing to One Table Issue

Edit - Cleaning up question to better reflect the actual issue: I'm using SQLMetal to generate database classes from our SQL Server db. Recently, I needed to add a table that had multiple foreign keys pointing to the same table. Using LINQPad to play around with the new tables, I was able to access properties for both foreign keys like ...

Adding new SQL commands directly to the LINQ designed class.

I vaguely remember reading an article a while back about being able to add queries to the designer.cs of the DataAccess layer (created by LINQ). So in other words if you want to add some SQL directly ,rather than adding and SP to the DB and adding it to the dbml (or rerunning SQLMEtal). You could just create another partial of the DB c...

How do I implement this command to prevent deadlocks with LINQ to SQL?

I would like to implement SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED in my project which uses LINQ to SQL. My understanding is that this will affect all select statements globally. Do I put this in my DAL which contains the context object? If so, how? Thanks! Mark ...

At a glance can anyone tell me why this Action is so slow?

This thing was not noticed to be slow at first because there were not many 'tree nodes' in the database. Now it's really slow, at a glance is there anything major that is wrong with this? I really need to optimize it and before I rework the entire thing I was wondering if anything stands out as being the real pain point. I have narrowed ...

SQL - Make this statement faster i.e. less duration, reads

Given the following tables: Orders (OrderID, OrderStatus, OrderNumber) OrderItems(OrderItemID, OrderID, ItemID, OrderItemStatus) Orders: 2537 records Order Items: 1319 records I have created indexes on Orders(OrderStatus) OrderItems(OrderID) OrderItems(OrderItemStatus) I have the following SQL statement (generated by LinqToSql) ...

Read-only LINQ to SQL

I'm using LINQ to SQL to access my database but I'm only reading, I never insert, update or delete anything. Are there ways to optimize LINQ2SQL for this? ...

getting an error with linq-to-sql on a table with a composite primary key

linq-to-sql is giving me this error "Can't perform Create, Update, or Delete operations on 'Table(Friend)' because it has no primary key." from a table with a composite primary key ...

What's wrong with this LINQ

I have a simple DTO that I'm trying to return via RIAServices and I keep getting this error: "Load operation failed for query. Unable to create constant value of type 'System.Object'. Only primitive types are supported in this context. Here's the query method: public IQueryable<SupportDbDTO> GetDbsRelatedToModel(string modelDtoId) { ...

Linq-to-sql Not Contains or Not in?

I'm building a poll widget. I've 2 tables, call them Polls and PollsCompleted. I need to do a linq query to get all the Polls that do not exist for a given user in PollsCompleted. I have the following sets: For Polls Where Active == True For PollsCompleted Where UserId == ThisUserId Where PollId = Polls.Id Now I need to get all Polls...

Website database duplicate records

On every page of my website a token is passed in as a querystring parameter. The server-side code checks to see if the token already exists in the database. (The token is a uniqueidentifider field in the database). If the token exists then it will use the existing one, if not then it will create a new row with the new token. The problem...

Comparing byte[] in LINQ-to-SQL and in a unit test that uses mocking

I have the following method: User IDataContext.AuthenticateUser(string userName, string password) { byte[] hash = PasswordHasher.HashPassword(userName, password); var query = from e in mContext.GetTable<User>() where e.Email == userName && e.Password == hash select e; return query.FirstOrDefault(); } Wh...