linq-to-sql

LINQ Submit Changes not submitting changes

I'm using LINQ to SQL and C#. I have two LINQ classes: User and Network. User has UserID (primary key) and NetworkID Network has NetworkID (primary key) and an AdminID (a UserID) The following code works fine: user.Network.AdminID = 0; db.SubmitChanges(); However, if I access the AdminID before making the change, the change neve...

LinqToSql and abstract base classes

I have some linq entities that inherit something like this: public abstract class EntityBase { public int Identifier { get; } } public interface IDeviceEntity { int DeviceId { get; set; } } public abstract class DeviceEntityBase : EntityBase, IDeviceEntity { public abstract int DeviceId { get; set; } } public partial class ActualLi...

How do you update an object with Linq 2 SQL without rowversion or timestamp?

I'm trying to take a POCO object and update it with Linq2SQL using an XML mapping file... This what what I have: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Business.Objects { public class AchievementType { public int Id { get; set; } public string Name { get; set; }...

How do I get the MAX row with a GROUP BY in LINQ query?

Hey all, I am looking for a way in LINQ to match the follow SQL Query. Select max(uid) as uid, Serial_Number from Table Group BY Serial_Number Really looking for some help on this one. The above query gets the max uid of each Serial Number because of the Group By Syntax. ...

Does LINQ's ExecuteCommand provide protection from SQL injection attacks?

I've got a situation where I need to use LINQ's ExecuteCommand method to run an insert. Something like (simplified for purposes of this question): object[] oParams = { Guid.NewGuid(), rec.WebMethodID }; TransLogDataContext.ExecuteCommand ( "INSERT INTO dbo.Transaction_Log (ID, WebMethodID) VALUES ({0}, {1})", oParams); The question ...

Using Linq with WCF

I am looking for any examples or guides to using Linq over WCF (n-tier application). Please specify if you are showing something for Linq-to-SQL or Linq-to-entities. I would like to see usage examples for both. I am wondering how things like deffered execution works over WCF (if it works at all)? Cyclic references support and so on... ...

LINQ to SQL Peculiarities

Hi, I'm encountering some peculiarities with LINQ to SQL. With a relatively simple query, I want to select some fields, but have the date fields formatted as strings, which I first achieved like this: var list = dataContext.MyLists.Single(x => x.ID == myId); var items = from i in list.MyItems selec...

What's wrong with Linq to SQL?

What's wrong with Linq to SQL? Or - what about Linq to SQL would make it unsuitable for a project, either new or existing? I want to hear about why you would not choose Linq to SQL for a particular project - including what project parameters make it unsuitable. ...

How can I wrap a transaction around Membership.CreateUser?

I'm using the asp.net SqlMembershipProvider and LinqToSql in a hobby/learning application. I have some user properties that I'm keeping in LinqtoSql, so my flow is: Membership.CreateUser -> MyClass.AddUserDetails. I'd like to wrap the whole thing in a transaction, so if the myclass bit fails I can roll back the membership bit. Any sugges...

LINQ Benchmarks in multitiered environment

I am involved in development of a tiered application that uses LINQ2SQL separated from the web server with a NET.TCP Binding on WCF. My questions are: What sort of measures should I take to achieve the best performance? Since the entity objects returned by the LINQ need to be converted to a IEnumerable list to be serialized everyt...

How to do a LINQ Outer Join of a SubTable?

I have a data tables with this type of setup. Table A AID AName --------------------- 1 A_Name1 2 A_Name2 3 A_Name3 Table B BID BName --------------------- 10 B_Name1 20 B_Name2 30 B_Name3 Table C AID BID --------------------- 1 10 2 10 2 20 2 30 3 20 3 ...

Why is LINQ to SQL converting my string parameter to a column name?

This Linq to SQL query ... Return (From t In Db.Concessions Where t.Country = "ga" Select t.ConcessionID, t.Title, t.Country) ... is generating this SQL: SELECT [t0].[ConcessionID], [t0].[Title], [t0].[Country] FROM [dbo].[Concessions] AS [t0] WHERE [t0].[Country] = ga ... when what I want is WHERE [t0].[Country] = 'ga' Any ...

Linq to SQL Class Regeneration

I've been using this nifty LINQ to SQL tool for a data access layer in an asp.net project. I keep making changes to the underlying tables and in order for the data classes to recognize the change I have to delete and readd the table which has changed. Is there some shortcut to regenerating the data layer? ...

LINQ to SQL Table Dependency

If I have two tables... Category and Pet. Is there a way in LINQ to SQL to make the result of the joined query map to a another strongly typed class (such as: PetWithCategoryName) so that I can strongly pass it to a MVC View? I currently have Category and Pet classes... should I make another one? Maybe I missing something here. Can a...

Zero-to-many relationship with Linq to SQL

I have a User class which may or may not have an associated Department. This is referenced through the foreign key DepartmentId, and the relevant field in the User table is set to allow nulls. When I set up my "Create User" form and select no Department, I get a conflict error on SubmitChanges(): The INSERT statement conflicted with t...

How do I add to a list with Linq to SQL?

I have a table in the database that I'm retrieving using LINQ to SQL, and as a part of my processing I want to add to this list, then update the database with the new items + any changes I've made. What I thought I could do was this: var list = (from item in db.Table select item).ToList(); [do processing where I modify ite...

LinqtoSQL and problems

I am using link to sql, I have a connected set of objects. I start out and do a linq statement like this Dim L= from II in context.InventoryItems select II Dim L2 = L.tolist The second line was so that I could narrow down where the problem was occuring. When the second line is hit I get an error "The EntitySet is already loaded and t...

What is the correct LINQtoSQL-ish way to do a table truncate?

I have a project with a formidable data access layer using LinqtoSQL for just about anything touching our databases. I needed to build a helper class that bridges some common crud operations from CLSA objects to LinqToSql ones. Everything has been operating swimmingly until I needed to do a truncate on a table and all I had were “delete”...

Is there a way to write a group by query in LinqToSql grouping not on a scalar value?

I have those maps in my repository. public IQueryable<AwType> GetAwTypes() { return from awt in _db.AwTypes select new AwType { Id = awt.Id, Header = awt.Header, Description = awt.Description }; } public IQueryable<Aw> GetAws() { return from aw in _db.Aws select new Aw...

Mapping computed properties in Linq-to-SQL to actuall SQL statements

I have created some extra functionality on my Linq-to-SQL classes to make things easier as I develop my applications. For example I have defined a property that retrieves active contracts from a list of contracts. However if I try to use this property in a lambda expression or in general in a query it either throws an exception that ther...