linq-to-sql

Storing images with LINQ to SQL: Converting byte array or stream to Binary

I am working with LINQ to SQL and my image fields are treated as Binary. It's no big issue to convert the Binary type to byte[] (you can just use the ToArray() method of the Binary object) when I need to render the images, but can someone tell me how to turn either a byte[] or Stream object into the Binary object so I can save it back t...

LINQ To SQL not saving to database

I have a very simple table and I can happily query it using LINQ To SQL, but when I do any save/updates the GetChangeSet method on my datacontext is always empty. My code is very simple (concatenated code from various classes): public static EntitiesDataContext EntitiesContext { get { return new EntitiesDataContext("Dat...

Linqtosql - joined rows

In Linqtosql how do I show items from multiple rows in a single field. eg I have a 3 table setup for tagging(entity, tag, entitytag) all linked via foreign keys. For each entity I would like to return the name in one field and then all relevant tags in 2nd field. eg Item1, tag1; tag2; tag3 Item2, tag4, tag5.... VB statements prefe...

Determine the source DataContext for a Linq to Sql query

In my application I have several DataContexts that connects to different databases with different schemas. In a custom user control I display the results of the query and let the user edit them, and when the user edits the data I want to persist the changes to the database. To do that I need a reference to the source DataContext (or at l...

How to do a WHERE...IN... clause in LinqToSql?

Bear with me, I'm beginning: How can I select multiple elements using a WHERE...IN... type of clause as in select * from orders where orderid in (1, 4, 5) in LinqToSql? I'd prefer not to have a lambda expression since they scare me. Thanks in advance! ...

LINQtoSQL Error: Sequence operators not supported for type 'System.String'

For some reason my code won't work. from tan in TANS where tan.ID.ToString().Count() != 1 select tan I want to select all IDs that are duplicates in a table so I am using the count != 1 and I get this error. NotSupportedException: Sequence operators not supported for type 'System.String' Help please? ...

ASP.NET-MVC (IIS6) Error on high traffic: Specified cast is not valid

...

Possible to modify the C# that Linq To SQL generates?

It would be really handy to be able to somehow say that certain properties in the generated entity classes should, for example, be decorated by (say) validation attributes (as well as Linq To SQL column attributes). Is it a T4 template someplace? Or are there other ways to skin the cat? ...

how to translate the SQL code "having" condition into LinqToSQL or LinqToEntites?

Could you tell me how to translate the following SQL code to Linq To SQL or Linq To Entites? The correst SQL code is: select CollectId,url,userid,pubtime from Collect group by url,collectid,userid,pubtime having pubtime >= (select max(pubtime) from collect d where d.url = collect.url ) order by Collect.pubtime desc Th...

TransactionScope Error against Sql Server 2000 - The partner transaction manager has disabled its support for remote/network transactions.

I am trying to set up a simple transaction for my Linq-to-Sql actions against my Sql 2000 database. Using TransactionScope it looks like this: using (TransactionScope transaction = new TransactionScope()) { try { Store.DBDataContext dc = new Store.DBDataContext(); Store.Product product = GetProduct("foo"); dc...

Generate lambda with Reflection Info

I have Enitity Type, Name of Primary Key and Guid of Primary Id. I want to get element of such Id in LinqToSql. model.GetTable<T>().Where(t => here equality ); I think I need to generate that Expression myself, but I dont know how :( ...

DataTable Query

Hi, I am new to LINQ. I am trying to find the rows that does not exists in the second data table. report_list and benchmark both type are : DataTable. Both these datatables are being populated using OleDbCommand,OleDbDataAdapter. I am getting an error "Specified cast is not valid." in foreach ... loop. I would appreciate your help. ...

Linq to SQL: How can I Order By a composite object?

I have the following Linq to SQL query, in which I'm trying to do a multi-column GROUP BY: return from revision in dataContext.Revisions where revision.BranchID == sourceBranch.BranchID-1 && !revision.HasBeenMerged group revision by new Task(revision.TaskSourceCode.ToUpper(), ...

"Cannot call methods on DateTime", and other limitations

Does anyone know of a definitive list of LINQ to SQL query limitations that are not trapped at compile time, along with (where possible) workarounds for the limitations? The list we have so far is: Calling methods such as .Date on DateTime no workaround found string.IsNullOrEmpty simple, just use == "" instead .Last() we used .Or...

How to access foreign key related column values using LinqToSql?

I'm trying to wire-up LinqToSql to be my data access layer and running into a few issues, probably due to my lack of experience with LinqToSql. I have two tables, one called Project and one called Employee. The Project has fields for OpenedBy and ClosedBy which are foreign key references to the Employee table, which has fields for Empl...

LinqToSql and the DataContext 101

I'm looking for a good article or two, or just an explanation, on how the DataContext, or dbml file, for LinqToSql, exactly works in LinqToSql. Is this a disconnected environment? Are the database connections still pooled by Sql Server? If I create an instance of my DataContext am I responsible to Dispose of it? How does it handle a mu...

Using LinqtoSql, how can I return values from a temp table in a SPROC?

I have a stored procedure that returns values from a temp table. In my DBML, it displays (None) for the return type. What is the trick to get it to recognize the columns from my temp table? CREATE PROCEDURE [dbo].[GetCategoryPriceRanges] @CategoryId int AS BEGIN DECLARE @MinPrice money, @MaxPrice money SELECT @MinPrice = MIN(ourP...

Best way to use Linq2Sql?

I'm struggling to think of a good way to use linq2sql, simply I want to use it, but I can't figure out whether it's best to wrap up the linq2sql generated classes inside my model classes providing some form of generic abstract base class / or interface for the common methods on my model classes like add, update, delete etc, or to extend ...

Is it possible to Serialize a LINQ object?

I'd like to serialize some LINQ generated objects and store them in a table as a binary field (Never you mind why). I'd like to be able to write some code that looks something like this: SerialTestDataContext db = new SerialTestDataContext(); relation_table row = db.relation_tables.First(); MemoryStream memStream = new MemoryStream();...

what wrong with this linq to sql

i get this error {"Method 'System.DateTime ConvertTimeFromUtc(System.DateTime, System.TimeZoneInfo)' has no supported translation to SQL."} when i try to execute this linq to sql var query = from p in db.Posts let categories = GetCategoriesByPostId(p.PostId) let comments = GetCommentsByPostId(p.PostId) ...