linq-to-sql

Signals in Linq to Sql?

Does anyone know of a way to do something similar to Django's signals using LINQ to SQL? I'm trying to record when new rows are inserted and when certain columns are updated, so I really just want pre_save and post_save signals. I can kind of do it with some models by using the partials defined like OnFooIDChanging() and OnFooIDChanged...

linq 'range variable' problem

Hello all, I have a strange problem when deleteting records using linq, my suspicion is that it has something to do with the range variable (named source). After deleting a record all targets for a customer are retrieved using the following statement: var q = from source in unitOfWork.GetRepository<db_Target>().Find() where source.db...

Inheritance of LINQ to SQL data context

If I inherit one DBML file from another DBML file, is it possible to visually create associations to the data classes from inherited DBML? ...

linq2sql, one to many through relations

I have OrgUnits, OrgUnitJobs, Employees, OrgUnitJobEmployee (this one may seem redundant in this context, its here fyi) tables. org units have jobs defined in OrgUnitJobs (1..n) employee (can also have many jobs) has jobs defined in OrgUnitJobEmployee table. and employee has a PrimaryJob (1..1) in OrgUnitJobs table, so how d...

How can I make sure my LINQ queries execute when called in my DAL, not in a delayed fashion?

I have a DAL that is composed of a bunch of methods that perform LINQ queries on my database. How do I ensure that before returning say an IEnumberable or something similar from the database, I ensure that the LINQ query is execute then, not in some delayed fashion only to be executed when the result is used? I know I can call .ToList(...

Is there a generic way to get a Linq2SQL Entity by its primary key?

Ok, the short version is that I have a Linq entity from a LinqDataSourceUpdateEventArgs and I need to handle the Update manually because MS was stupid. I can get the Table object from the data context, which allows me to, well, this: var newObj = e.NewObject; var table = FormContext.GetTable(e.NewObject.GetType()); table.Attach(newOb...

How can I Stream bytes from a TSQL varbinary table column in .NET?

In a SQL Server 2008 database, I have a table with a column of type varbinary. Currently, I am using LINQ to SQL to access the database. I already know that I can delay the loading of the column. However, I wish to consume less memory by not loading all of the bytes from that value. Ideally, I would like to have a Stream to those bytes. ...

LINQ to SQL in 3-layer architecture

I currently use the 3-layer architecutre (DAL, BLL, Presentation Layer). I am wondering how I can implement the 3 layers architecture using LINQ to SQL. I don't know whether LINQ should be in DAL or BLL. LiNQ seems the fusion of both DAL and BLL. Does anyone implement LINQ in 3-layer architecture before? ...

store PDF file in DB as byte

Hi: I am using Asp.Net MVC. in my project while uploading PDF file we convert the PDF file into byte then store it in DB. but i got the following exception. " String or binary data would be truncated. The statement has been terminated." Can any one solve this issue.I got the exception righ here context.SubmitChanges(); Tha...

Most efficient way to auto-hookup a foreign key in LINQ

I have two tables for tracking user sessions on my site. This is a gross oversimplification btw : Campaign: campaignId [int] campaignKey [varchar(20)] description [varchar(50)] Session: sessionDate [datetime] sessionGUID [uniqueidentifier] campaignId [int] campaignKey [varchar(20)] ...

how to write with LinQ to SQL?

SELECT P.ProductId, P.ProductCategoryId, P.ParentProductCategoryId, P.ProductName, PC.Name AS Category, P.Price, P.ProductYear FROM dbo.ProductCategory AS PC INNER JOIN (SELECT dbo.ProductCategory.ParentProductCategoryId, dbo.ProductCategory.ProductCategoryId, dbo.ProductCategory.Name AS CategoryName, ...

Why do people use linq to sql?

Given the premise: There are competent sql programmers (correlary - writing sql queries are not an issue) There are competent application developers (correlary - there is simple/strong/flexible architecture for handling connections and simple queries from code) Why do people use linq to sql? There is overhead added to each transact...

Access Linq result contained in a dynamic class

I'm using DbLinq which should be the equivalent of Linq2SQL for this question. I'm need to generate a Linq2SQL query where I specify the columns I want returned at runtime. I can achieve that using the Dynamic Linq extension methods but I can't work out how to extract the result. string someProperty = "phonenumber"; string id = "1234"; ...

How to write dynamic Linq2Sql compiled queries?

I'm having performance issues with Linq2Sql compared to raw ADO.NET which has led me down the path of compiled queries. I have got this far so far public static readonly Func<MyDataContext, WebServices.Search.Parameters, IQueryable<image>> Compiled_SelectImagesLinq = CompiledQuery.Compile<MyDataContext, WebServices.Search.P...

Linq to SQL question - specifying columns then modifying column

Hey, I'm trying to write a linq to sql method that handles sorting, paging, and filtering for an ajax grid. I created a partial class Employee that has a TotalRecordCount, as I need to pass this to the javascript for setting up the pager. The problem is that it won't build because I can't set the AnonymousType#1.TotalRecordCount, it's re...

When will linq to sql be phased out? Is entity frameworks (replacement) released yet?

When will linq to sql be phased out? Is entity frameworks (replacement) released yet? ...

How can I make this LINQ query cleaner?

I have recently written a LINQ query to get a Dictionary containing the last 6 month's placement amounts. It is returning a Dictionary of Month string - Decimal Amount pairs. It seems kind of cludgey. Any of you LINQ masters out there able to help me refactor this to make a bit cleaner? /// <summary> /// Gets the last 6 months of Pla...

LINQ to SQL with stored procedures and user defined table type parameter

I am using LINQ to SQL with stored procedures in SQL Server 2008. Everything work well except one problem. L2S cannot generate the method for the stored procedure with user defined table type as parameter. Method signature in dbml design panel use object for parameter type instead of table type and when I tried to compile I got error: ...

How can I make LINQ to SQL use a connection string which is being modified at runtime?

I'm experimenting some difficulties trying to use Connection String Builders (ADO.NET) within LINQ to SQL. Let me show you guys what I'm trying to do: the app.config file: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> </configSections> <connectionStrings> <add name="LoremIpsum" ...

ChangeConflictException in Linq to Sql non-concurrent updates

I'm using LINQ to SQL, and having a bit of an issue incrementing a view counter cross-connection. The teeny bit of code I'm using is: t = this.AppManager.ForumManager.GetThread(id); t.Views = t.Views + 1; this.AppManager.DB.SubmitChanges(); Now in my tests, I am running this multiple times, non-concurrently. There are a total of 4 c...