linq-to-sql

LINQ: Prefetching data from a second table

Hi, I'm trying to pre-fetch some foreign key data using a linq query. A quick example to explain my problem follows: var results = (from c in _customers from ct in _customerTypes where c.TypeId == ct.TypeId select new Customer { Custo...

linq to sql - how do i rewrite the following...

Is there a better way to create the following linq to sql query? I am trying to get all Company Names that start with a number [0-9]... var suppliers = from s in context.Supplier where SqlMethods.Like(s.CompanyName, "0%") || SqlMethods.Like(s.CompanyName, "1%") || SqlMethods.Like(s.CompanyName, "2%") || SqlMethods.Like(...

Storedprocedure returns xml but linq replaces ' " ' with '\'

Hi, I have a stored procedure in sql server that returns xml. The problem I'm facing is that the returned result which is of type ISingleResult contains the string for the xml returned by the stored procedure and in this string all the ' " ' are replaced by '\'. So I can't parse the xml. Why is this happening? ...

General best practice for updating a record and its associated relationships in Linq-to-SQL

I have a very general question about updating a record in Linq-to-SQL. Suppose, in my data model, I have a base record (Table - Person) with an m:m relationship to a set of Categories (Table - Category). Therefore, I have an associative table (PersonCategory) that has foreign keys to both a PersonID and CategoryID. When I want to upda...

LINQ-to-SQL Search on dynamic columns?

Using the System.Linq.Dynamic namespace I am able to construct a generic column list to search based on the columns present in the current usercontrol (a searchable grid we use in various places). The process is simple, take the column list visible to the current user, append the columns into a dynamic query expression in a where clause...

LINQ to XML or SQL Server 2005 XML DML?

I'm writing an app that retrieves RSS feeds on a scheduled daily basis and saves the contents of each feed as XML Data in a SQL Server 2005 database. I want to display the aggregated items, sorted by date, for example, from the saved feed data in my app in Asp.Net GridViews. My question is: should I use LINQ to XML to query the feed da...

linq2sql: Explicit construction of entity type '#some type#' in query is not allowed - also using join

Hi there, I am having a problem mapping. I was reading scottGU post of "data shaping features" - http://weblogs.asp.net/scottgu/archive/2007/06/29/linq-to-sql-part-3-querying-our-database.aspx but i have tried this IQueryable<AccessRights> accessRights = from t1 in this.db.AccessRights ...

Make a dynamic query with Linq using a drop down list selected option in Asp.net MVC

Hi everyone! I'm trying to accomplish this with Linq to Sql and Asp.Net MVC: I have a Drop Down List with options Country, City and State. And beside it, there is a textbox. So, an user will, for instance, select City and will type "new york city" in the textbox and the application will show himm the results of his choice. So, how ca...

Refactoring Linq to Sql

Is there a way to refactor linq to sql and take advantage of late evaluation? Is there a way to reuse object initilizer code? I have business objects that are persisted in a database and hydrated via a separate linq to sql layer. I would like to be able to reuse code from multiple queries that do the exact same thing. The portion of t...

LINQ problems with NText, Text and Image on SQL server

Apologies up front, because this isn't a question but a solution - but it took a lot of searching to find out the answer and google wasn't much help, so I wanted to give something back to the community by providing the error and the solution to help future googlers. When using LINQ to SQL, I ran into a problem when submitting changes (t...

LINQ to SQL: errors from stored procedure are ignored after result set is returned

I'm using LINQ to SQL to call a stored procedure. This stored procedure currently returns a resultset and then has some raiserror statements being triggered after the resultset is retrieved (I'm writing tests for stored procedures, in case you're wondering why I'm doing this). When LINQ to SQL calls the proc and it gets a resultset bac...

linq-to-sql implementing row level save/commit/rollback

Is there a recommended way to implement individual row-level change tracking? such that when a change is made to more than one row before a save is called, changes that the database doesn't reject move forward, the ones that don't aren't? I have am trying to figure this out for two projects a ticketing database, and an asset management d...

does linq-to-sql entity serialization work out of the box?

If I try to serialize a linq-to-sql entity, will it by default serialize only the primitive fields or will it try to access the relationship fields as well? If it tries to grab relationship fields, is there a way to override this? ...

Sql Query to Linq To Sql

Hi, I have some difficulties when it comes to multi-table query in Linq to Sql. I have 3 tables: Product Row (with Fk-ProductId) Price (with Fk-RowId) I'd like to retrieve the min(Price) for a product. I was able to get the right Sql query, but now I need to 'translate' this query into Linq To Sql. Can you please help me ? Here the...

Linq to SQL error : An order by expression can only contain non-constant scalars...

I'm using a GridView and a LinqDataSource to view the Categories table. I set the Gridview to enable sorting. Sorting generally works except when i clicked on the header of the Description column. "An order by expression can only contain non-constant scalars that are order comparable by the server. The expression with type 'NText' is no...

Linq SubmittingChanges after assigning new object

If I make changes to an existing linq object by assigning a "new" object of the same type (with different values), SubmitChanges does not make the changes in the database. why not? existing= new Data.Item{a=1, b=2...}; vs existing.a= 1; existing.b= 2; ...

How to return nested, one to many relationship in a ASP.NET MVC json response?

How would you format a Json response to include nested, one to many related data? My simple JQuery Autocomplete example. The Linq2Sql is within. The first part of this question answered here. This uses a repository with Linq 2 SQL to send the response: public IQueryable GetProductIDs(string myPrefix, int limit) { return from z i...

Circular Reference Problem while calling a Web Service created in .net 3.5

Hi, I have implement a small web service using .net 3.5. I have used linq to sql classes for accessing the database. And I have written following webmethods as follows : using System; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml.Linq; using System.Collections.Ge...

problem updating row in Gridview with bound combobox

i have the following gridview <asp:GridView ID="GridView3" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="CommentsDataSource"> <Columns> <asp:BoundField DataField="Firstname" HeaderText="Firstname" SortExpre...

How to create custom xml tags using .net web services?

I am using LINQ-To-SQL for database. I am returning the xml content from my web service as follow: The code: DataClassesDataContext dc = new DataClassesDataContext(); [WebMethod] public List<Books> getBooks() { return dc.Books.ToList(); } Output: <ArrayOfBook> − <Book> <bookID>1</bookID> <title>Programming wi...