linq-to-sql

LINQ to SQL - retrieve object, modify, SubmitChanges() creates new objects

I've been battling this for a while. I'm trying to implement a many to one association. I have a bunch of rows in a table, called readings. These accumulate over time, and every now and then I want to export them. When I export them I want to create a new object called ExportEvent, to track which rows were exported, so they can be re-exp...

Moq and DataContext

I am new to Moq and need to know if I am doing this right. In AccountController.cs I have this: int id = _userRepository.GetProfileFromUserName(userName).ProfileID; UserRepository is mocked, but ProfileID comes from DataContext, so I did this in my AccountControllerTests.cs: mockUserReposository.Setup(gp => gp.GetProfile...

Linq to SQL mapping data without a DataContext

Is it possible to access Linq to SQL mapping data without a DataContext instance? I ask because I am writing some audit data generation code that will only trigger for some entities and some entity columns. I would like to fix up this meta data in a static constructor prior to any Linq DB access. For example from a performance perspect...

LINQ To SQL exception with Attach(): Cannot add an entity with a key that is alredy in use

Consider this typical disconnected scenario: load a Customer object from SQL Server using LINQ To SQL user edits the entity, and the presentation tier sends back the entity modified. the data layer, using L2S, must send the changes to SQL Server Consider this LINQ To SQL query whose intention is to take a Customer entity. Cust cust...

Returning Custom Classes as IQueryable so doesn't have 'has no supported translation to SQL' error

I have the below call in my repository where I return IQueryable of Node (my business object class) then I have a filter function in my service layer which adds to the IQueryable call and filters the repository function GetNodes by id. When I return the FilterById as a list (so it executes) I get error -- The member 'bo.Node.Id' has no ...

using linq, can I still have 3 tiers or do I have to pass the context around?

With linq2sql, is it possible to have a 3 tierd app or so I have to pass the dbcontext around since its an expensive call? ...

ASP.NET MVC - Join Tables using LINQ

My application is structured as: namespace DomainModel.Abstract { public interface IContentItemsRepository { IQueryable<Content> ContentItems { get; } IQueryable<Category> Categories { get; } IQueryable<ContentCategory> ContentCategories { get; } } } namespace DomainModel.Entities { [Table(Name ...

Performance regarding return type for LINQ query compatible with automatic sorting

Hi! this isn't really an issue, but more of a concern that I would appreciate some input on please. Winforms C# .net3.5[sp1] Visual Studio 2008 using Linq2Sql (more specifically PLINQO...which is fantastic btw!). I have a resultset returning +/- 19000 rows of data (with about 80bytes of data per row) and opted to push the data retrieva...

LINQ-to-SQL and SQL Compact - database file sharing problem

Hello. I'm learing LINQ-to-SQL right now and i have wrote a simple application that define SQL data: [Table( Name = "items" )] public class Item { [ Column( IsPrimaryKey = true, IsDbGenerated = true ) ] public int Id; [ Column ] public string Name; } I have launched 2 copy of application connected to the same ...

Saving EntityRef and EntitySet objects Automatically

Say I have an entity that looks as follows public Order OrderEntity { EntityRef<Customer> CustomerEntity; EntitySet<OrderDetail> OrderDetailEntity; ... ... } When I save a OrderEntity, L2S, will want to also save the entity in CustomerEntity and all the entities in OrderDetailEntity. Sometimes we want this behavior and so...

how does linq2sql handle tables with just FK in it?

I have a mapping table like: Article_to_Categories ArticleID CategoryID How would I insert into this table using linq2sql? ...

Using LINQ To SQL with multiple databse tables

I have an employee class with as follows: public class Employee { public string FirstName { get; set; } public string LastName { get; set; } public string UserName { get; set; } public string Password { get; set; } } The properties FirstName and LastName are stored in Employee table in Database1. UserName and Pa...

PredicateBuilder and nested predicates

I'm trying to use the Predicate from Albahari to create a TSQL statement like: select * from channel where channel.VendorID IN (@vendorIDs) AND channel.FranchiseID IN (@franchiseIDs) or a predicate like : c => (c.VendorID = x || c.VendorID == x2 ...) && (c.FranchiseID == f || c.FranchiseID == f2 ...) but I'm having troubles. Here is ...

How to do an update with linq to sql?

I have two tables in my DB Class Student One Class has many Students What's the best,more elegant way to update the students of one class, using Linq? ...

LinqToSql + calling .Count fails in production only

Hello, This should be very simple, but its very frustrating. I have a LinqToSql as below, it works fine in development but when i move the code to production it blows up on .Count update, resolved the issue, but dont understand why i had to... Please explain if you can, im confused. The code below works fine in development, in orde...

LinqToSql InsertOnSubmit memory leak?

I am trying to isolate the source of a "memory leak" in my C# application. This application copies a large number of potentially large files into records in a database using the image column type in SQL Server. I am using a LinqToSql and associated objects for all database access. The main loop iterates over a list of files and insert...

SQL to Linq translation with inner join and 2 left joins (with sub-query)

Hi there! I have the following query which works fine in SSMS. Im using LinqPad (C#) but really puzzling to succeed with the left outer join in LinqToSql: SELECT DISTINCT A.LocID, V1.PrfValue AS pID, V2.PrfValue AS sID, D.DivisionManager, A.IsApproved, A.DateCreated FROM dbo.Locations AS A INNER JOIN dbo.D...

Can you use a C# library in a AMP-server?

Is it possible for me to build some database functionality in a C#-library (using LINQ 2 SQL) and then somehow import it into a php (joomla) project? ...

How to Detect Select n+1 problems in Linq to SQL?

What is the best way to detect Select n+1 problems if i am using linq to SQL, right now we are working on a project and it seem to be pretty slow to display some lists. What is the best method to detect this? ...

Linq - 2 tables - Sum

Hi, i have 2 tables: Asiento ******** Id_Asiento integer key Fecha date It_Asiento ********** Id_Asiento integer Forenkey Importe float I wan to do This SQL Query with Linq select Asiento.Id_Asiento, Asiento.Fecha, Sum(It_Asiento.Importe) From Asiento join It_Asiento on Asiento.Id_Asiento = It_Asiento.Id_Asiento and It_Asiento.Im...