linq-to-sql

Subquery is not supported on 'IsDeleted' of type 'Entities.Product'

I'm using Linq to SQL and trying to filter data using DataOptions and AssociateWith. I have a table called Products that has a primary key called Id and a flag called IsDeleted with sql-datatype bit. When I use the following code I get "Subquery is not supported on 'IsDeleted' of type 'Entities.Product'" exception on AssociateWith meth...

How to check for deletions on a LINQ to SQL EntitySet

I have an entity that has a collection of associated entities in an EntitySet. Ultimately, I'm trying to report on some changes that have been made to this entity. I will most likely use the GetModifiedMembers() method to do this, and I'm guessing I can just do the same with each entity in the EntitySet, but I'm not sure how to tell if t...

Customizing Linq to Sql DataContext

Is there anyway simple ways to add a property to Linq to Sql generated entity to reference its DataContext? For example: var myContext = new DataContext(); var product = context.Products.Where(p => p.Id == productId).SingleOrDefault(); and product entity has a property called "Context" (product.Context) that has a reference to the my...

Can I make a generic CompiledQuery that accepts multiple tables and generic types?

Hello, I have multiple tables with an "id" component. I'd like to use LINQ to get an item from one of these tables with the correct LINQ-To-SQL type, but only using one CompiledQuery. Here's an example that works currently. Say the object type defined in the DBML is "myitem" and its table is "myitems". var getOneItem = CompiledQu...

Linq to SQL: Asking if a date is empty

I've got a new instance of an object in a Linq DBML, but don't know of the test if the a date field is empty. I have tried: If d Is Nothing OrElse IsDBNull(d) OrElse d <= Date.MinValue Then TextValue = "nada" Else TextValue = FormatDateTime(d) End If But the result is "12:00:00 am" edit: Changed variable name the d edit: Pleas...

Can linq2sql do this without a lot of custom code?

Just dipping my toes into Linq2sql project after years of rolling my own SQL Server DB access routines. Before I spend too much time figuring out how to make linq2sql behave like my custom code used to, I want to check to make sure that it isn't already "built" in behavior that I can just use by setting up the relationships right in the...

LinqToSQL and the exception " ExecuteReader requires an open and available Connection."

Hi guys, I have a collection called dbUsers of type IQueryable These are pulled from a linqtosql database context i.e. IQueryable<Data.LinqToSQL.User> dbUsers = DBContext.Users Calling ToList on this object: IList<Data.LinqToSQL.User> users = dbUsers.ToList(); Results in an exception: ExecuteReader requires an open and available...

How to lambda the group by data on a LINQ to Sql results?

I get the data from the database like this. Dim query = From t1 In TBL1 _ Join t2 In TBL2 On t1.ID Equals t2.ID _ Join t3 In TBL3 On t1.ID Equals t3.ID _ Group Join t4 In t1 _ On t1.ID Equals t4.ID _ Into t4_Grp = Group _ Select t1, t2, t3, t4_Gr...

Are there any major features missing from Linq-to-Sql?

What major features are missing from Linq-to-Sql? Compatibility with other major SQL Database Engines (MySQL etc) Mapping Many-to-Many relationships Any others? I have already developed a major project with Linq-to-Sql at it's DAL Heart. i hadn't developed using a relational data mapper before, so it was a learning curve coming from ...

Sql to Linq - Reverse

I have a truckload of xsd with plain SQL queries. I want to migrate to LINQ. Is there a automated way to generate LINQ equivalents from SQL statements? ...

L2SQL or EF?

Hi guys I am wondering what's your opinion about this. I have used L2SQL in my last project, and its a great OR mapping system. I have never used EF yet, however I have read that the Microsoft team seem to give it more importance than the L2SQL. What's your opinion? (edit: multiple duplicates - see comments, most notably: Entity Fra...

Is mixing WPF, LinqToSql and multiple threads a bad idea?

My situation is roughly similar to this guy except that I don't need change notifications right now I have a WPF App displaying a hierarchy. The children for each node are retrieved using a LinqToSql query. The app works perfectly when there is one thread. Now I'd like to make things a bit faster.. by loading children asynchronously. F...

If all my sql server database access is done thru stored procedures.....

If all my sql server database access is done thru stored procedures, and I plan on continuing that practice, is using linq2sql and/or the entity framework for future projects an unnecessary layer of complexity that doesn't add much value? Related question: is Microsoft trying to steer developers away from relying on stored procs for dat...

How do I write a User Defined Function?

I would like to write this as a user defined function: private double Score(Story s){ DateTime now = DateTime.Now; TimeSpan elapsed = now.Subtract(s.PostedOn); double daysAgo = elapsed.TotalDays; return s.Votes.Count + s.Comments....

Linq to SQL: execution order when calling SubmitChanges()

I have 2 related database tables which in simplified form look like this Product( product_id, name ) ProductSpecs( spec_id, product_id, name, value ) Foreign key is set via product_id field and ProductSpecs table has a unique constraint on (product_id, name) pair. Now in my ASP.NET MVC application when user edits product...

LINQ to SQL Insert

Hi, i'm using LINQ To SQL to perform an insert via db.table.InsertOnSubmit(). I'm wondering if there is a way to reproduce the T-SQL version of the 'where not exists (select etc etc) begin insert into etc etc end' as one single query? Thanks, Martin ...

SQL to L2S Translation Help

So here is the original query SELECT SUM(PickQty), SUM(ReqQty), AssignmentID, StopID FROM PickRequest GROUP BY AssignmentID, StopID in LINQ from a in dbReqs group a by new { a.AssignmentID, a.StopID } into pr select new { Assignment = pr.Key, StopID = pr.Select(s=> s.StopID), PickQty = pr.Sum(p=> p.PickedQty), Count = pr.Sum(c => c.Re...

ASP.NET MVC Authorization based on role membership or data relation (ownership)

I'd like to extend the AuthorizeAttribute in ASP.NET MVC so that it supports the concept of a user's authorization being based on their role membership OR "ownership" of the data in question. I'm using LINQ2SQL for data access. There is a similar question at http://stackoverflow.com/questions/390930/asp-net-mvc-authorization-using-roles....

LINQ to SQL Primary Key requirement for inserts fails

I'm working on better understanding Linq-to-SQL before using on a real project, so I'm playing with it on a little side project. I've a table that I'm trying to update via DataContext.SubmitChanges() and it's failing due to primary key constraints. I have no control over the table itself (I can't add an actual ID column), so instead ...

LINQ to SQL query fails using two Contains statements

I have two tables, DH_MASTER and DH_ALIAS. DH_MASTER contains information about a person, including their name. DH_ALIAS contains AKA records about the person. The tables are linked by the Operator field which is a primary key in DH_MASTER. The users want to search by the name stored in DH_MASTER as well as search through all of thei...