linq-to-sql

Display other fields besides just the foreign key Id in a list using Linq to sql

hello, What is the best way to display the username instead of the Author_Id (foreign Key) when I display a list of records. I am using Linq to Sql on this project. <% foreach (var item in Model) { %> <tr> <td> <%= Html.Encode(item.Title) %> </td> <td> <%= Html.Encode(item.Author_Id) %> <% } %> ...

How to serialize and save an object to database as Xml using Linq to SQL

I were using FileStream to Serialize an Object to Xml and Save to the disk Stream str = new FileStream(@"serializedstate.xml", FileMode.OpenOrCreate) XmlSerializer x = new XmlSerializer(typeof(GridState)); x.Serialize(str, new GridState { GridName= txtGridName.Text, GridColumns = GetGridColumnStates() ...

Return base class in LINQ for stored procedure causes stackoverflow

I have quite complex SP which returns base class (basecontent). I have inheritence with about 30+ child classes (like "page", "news", etc). When I return other types from SP everything works fine, but this one drives me crazy. I am quite experienced with LINQ and already tryied to recreate SP, verified outout, etc. But this call fails ...

WCF Linq to SQL Table - System.Data.Linq.Table cannot be serialized.

I can't figure this out as I go through demos that seem to work. I have a WCF service I was trying to use Linq to SQL with. However, all I ever get is the error System.Data.Linq.Table cannot be serialized. So I started with my own class thinking I could build it back up until get the error. Problem is I get the error even trying to use ...

How did you learn & master C# LINQ to SQL?

A book? An online tutorial? Stackoverflow? University? Trial and error? I have been using LINQ to SQL and I want to learn how to use it better because I feel like I can only do very basic things and I don't really understand how to use the good features. For example I have no idea what this means: public static IOrderedEnumerable<TSour...

OrderByDescending() per MSDN, what on earth does this mean?

Can someone please help be take apart the elements here and help me understand what they are? public static IOrderedEnumerable<TSource> OrderByDescending<TSource, TKey>( this IEnumerable<TSource> source, Func<TSource, TKey> keySelector ) What is TSource and TKey? What is a keySelector? What the heck is an IOrderedEnumerable? ...

Using LINQ to SQL to populate image

Good afternoon all, a little puzzler for you. I have a sql table that contains an AccountId and an AccountLogoFilePath (the images are stored in a folder rather than in the table itself). How would I go about using LINQ to SQL in populating an image using this file path method (in c#) I've done something similar in SSRS so I am asusmi...

Handle a Dynamic Select With Dyanmic Linq

I am using the Dynamic Linq Library that Scott Guthrie describes here. Scott Guthrie's examples are great and I have used the dynamic Where statements quite a bit. Now, however, I am faced with a situation where I need to use the dynamic select functionality. Scott Guthrie shows a screenshot of this functionality (in the very last...

Can't add a record twice with Linq to SQL

Hi there, In the legacy system I look after I have to add the same record to a table, twice. There is an identity on the table that increments with each new record. If I do the following I get the error: "Cannot add an entity that already exists" Is there a way to add a record twice without creating another PricingSnapshot object? ...

Better way of refreshing DataGridView.DataSource

Currently I have a DataGridView in my app which I fill from my Linq-to-SQL classes like so ... /// <summary> /// Delegate to update datagrid, fixes threading issue /// </summary> private void updateInfo() { // Linq to datagridview; display all var query = from n in dbh.Items select n; itemData...

C# - Linq-To-SQL - Issue with queries

I am thoroughly frustrated right now. I am having an issue with LINQ-To-SQL. About 80% of the time, it works great and I love it. The other 20% of the time, the query that L2S creates returns the correct data, but when actually running it from code, it doesn't return anything. I am about to pull my hair out. I am hoping somebody can...

Problem with LINQ query

The following works fine: (from e in db.EnquiryAreas from w in db.WorkTypes where w.HumanId != null && w.SeoPriority > 0 && e.HumanId != null && e.Seo...

Sort blank entries to bottom of LINQ query.

I am trying to sort a LINQ to SQL query based on two fields. The first field is occasionally null which automatically sorts to the top of an ascending query. Is there any way to make the null entries sort to the bottom? Here is an example: From x in SampleDataContext.Event _ Order By x.Date, x.Sequence_Number _ Select x.Date, x.Seq...

LINQ to SQL and a running total on ordered results

I want to display a customer's accounting history in a DataGridView and I want to have a column that displays the running total for their balance. The old way I did this was by getting the data, looping through the data, and adding rows to the DataGridView one-by-one and calculating the running total at that time. Lame. I would much r...

Linq to Sql Criteria in String Array

I have say three tables. Projects Id Name Categories Id Name ProjectCategories Id ProjectId CategoryId I now have an array of strings which represents categories the user has elected to search on. I now need to find all the projects that have those category attached to them. I tried; string[] searchTerms = new string[2...

linq query with group

I'm having a table which contains userId, regBy, regDate and so many.. I need a out of regDate, regBy and count(userId). How can a query this using LINQ.. ...

LINQ variable to list of string without using column names?

In an C# ASP.Net MVC project, I'm trying to make a List<string> from a LINQ variable. Now this might be a pretty basic thing, but I just cannot get that to work without using the actual column names for the data in that variable. The thing is that in the interests of trying to make the program as dynamic as possible, I'm leaving it up t...

LINQ2SQL Doesn’t return the same result as T-SQL…

I’ve the following tables: Paciente -> PacienteTag -> Tag The typical N:M between Paciente and Tag with an intermediary table. I want to obtain how many patients have each tag. Simple: SELECT Tag.TagName, COUNT(PacienteTag.TagId) AS Totals FROM Tag LEFT JOIN PacienteTag ON Tag.TagId = PacienteTag.TagId GROUP BY Tag.TagName ORDER BY ...

LINQ TO SQL error: An attempt has been made to Attach or Add an entity that is not new...

"An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported." I have scene a lot of solutions dealing with the Attach() method but I'm just trying to add in a new record. Not sure what is going on. Here is my code, It is failing on the star'd line.: ...

How to delete and insert records with the same primary key using Linq transactions

We have a single table in the database that represents a bunch of divs in our web page. Each div has a pixel width, height, top, and left saved as individual records in the table. It has a primary key. We load all divs from the table to the web page, the user rearranges the squres, then in a single transaction saves the altered square...