linq-to-sql

Error when trying to join a view in linq-to-sql

While trying to extract data from a view by joining it with two other tables, I'm getting the following error: "SQL Server does not handle comparison of NText, Text, Xml, or Image data types." And here is the query: var expeditions = from VE in context.ViewExpeditions join SIAGR in context.SiteInAdviseGoodsRef...

Save changes in Linq-to-SQL

So, here is my hopefully unique spin on this common problem. I do my query, get my objects then pass the object into a form where it populates the form with the data from the object (this is not passed in by reference). I then edit the values of the object that was queried (via the form) and then return a new object constructed from th...

problem with a LINQ To SQL query

Consider a new CMS and one of the features that we must add to the system is the option to create a custom forms with different inputs like text, select box etc. We managed to finish this part and now we are building the result part which needs to show the result that sent through the custom form. We have a FormsOrders table which stor...

LINQ 2 SQL query does not work with a function call

Hi all, I am quite sure this question has already been asked several times and I do apolgize for asking it once again, but I made a few research and unfortunately I did not find my pleasure on the internet... I have a IQueryable like this : triggers = triggers.Where(t => GetIdFromName(t.Name) == filter.Id.ToString()); The function G...

The full-text query parameter for Fulltext Query String is not valid

I am using Full Text Search with LINQ in my application and as this is not supported by LINQ I use a table-valued function workaround. The function is created on SQL Server 2008. Surprisingly, I get error “The full-text query parameter for Fulltext Query String is not valid” when I search for a simply text e.g. “manager” I used SQL Ser...

SQL Exception on immediate reconnect

I have a winform app that uses LinqToSql as it's DAL. There is a Central SQL DB and each laptop has a local SQLExpress DB. A seperate module, using Merge Replication, keeps the two in sync. When connection is lost to the central DB it 'fails over' to the local. This works great. However, when I regain conection to the central db, if...

Insert with Linq-to-SQL an object determined through reflection

I am trying to populate a row in a table given a key value list Using DataContext.Mapping I am able to locate the correct table (given a table name) and create a row. // Look up the table MetaTable matchedTable = null; foreach (MetaTable tableMetaData in db.Mapping.GetTables()) { if (table.Equals(t...

How to Remove or Revert DataContext.DataLoadOptions?

First let me start by explaining my use case: Say there is a database "Cars". In that database, each row might have Make, Model, EngineType, etc. I have a page that is essentially a view of a single "Car" record, displaying its various stats. In that page, I have a user control that calculates and displys various MPG stats based on the ...

LINQ Join (Left Outer) with Take(1)

I have the below LINQ that is returning zero IF there aren't any Addresses(Inner Join). How would I make this an Outer Join and then only Take(1)? var results = query.Join( DB.tblAddresses.Where(t => t.AddressTypeID == 'm' || t.AddressTypeID == 'b').OrderByDescending(x => x.AddressTypeID), p => p.PersonI...

Combine my Attributes on a Linq to SQL Entity Property

I have a Linq to SQL dbml.cs file with this in it: [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_PantsName", DbType="VarChar(248)")] [global::System.Runtime.Serialization.DataMemberAttribute(Order=3)] public string PantsName { get { return this._PantsName; } set { if ((this._PantsName != value)) { this._PantsName = val...

Child table loading with LinqToSql and RIA services

I am using LinqToSql on a project, and Ria services to expose it as an IQueryable. I want to send my Product table along with its child tables (e.g. ProductStatus, ProductCategory) To do this I am using the standard public IQueryable ProductSelect() { DataLoadOptions loadOpts = new DataLoadOptions(); loadOpts.LoadWith<Product>(p => p....

LINQ2SQL: how to delete entity by retrieving it from datagridview?

Hi2all! I have a datagridview and attached list of Employees to it, somthing like this: IQueryable<Employee> data = (from em in db.Employees where em.StationID == stationID select em); dgvView.DataSource = data; Now I want to delete specific Employee by selected row in datagri...

How do I get Linq-to-SQL to ignore columns that are modified by INSERT triggers?

There's a column on one of my tables that's being updated by various INSERT/DELETE triggers in my database - the triggers perform some calculation based on the contents of linked tables and store the result in a column on the base table for easier querying, etc. Linq-to-SQL is throwing a ChangeConflictException when I try to update thes...

LinqToSql associations loading

This may have been asked already, but I can't find it, so here goes. We have a generic read of a table, using Context.GetTable( ) and then attaching an expression to find the single record in the table. This table has associations. Unfortunately, we're trying to change a field on which an association is made, so; Foo is parent of Bar o...

LINQ to SQL Group by C# problem

I recently started to use LINQ to SQL and i have a minor complex query i need help with. I've got a table in my database called MovieComment, with the following columns: CommentID UserID MovieID Comment Timestamp So, what i wanna do is to group the comments on MovieID and save them into my object called Movie, where the MovieID is be...

Eager Loading Children for a LINQ stored procedure call

I have a special stored procedure that returns a List of Distributors from my database. I then iterate through the loop of Distributors and output the results to a web page. However, I need to load the State and the Country for each Distributor. I would rather do this one time, before the loop so that the page is faster. This is my c...

LINQ To SQL Dynamically Sorting

I want to pass the sort field and direction dynamically to the LINQ to SQL codes. But I could not find the way to perform like that because if I could not write users.OrderBy(d => Field); Is there any way to pass the dynamic field to sort? Thanks. private static IQueryable<user> GetUserData(String Field, String Direction) { User...

Recursively (?) compose LINQ predicates into a single predicate.

(EDIT: I have asked the wrong question. The real problem I'm having is over at http://stackoverflow.com/questions/3782940/compose-linq-to-sql-predicates-into-a-single-predicate - but this one got some good answers so I've left it up!) Given the following search text: "keyword1 keyword2 keyword3 ... keywordN" I want to end up with t...

Compose LINQ-to-SQL predicates into a single predicate.

(An earlier question, http://stackoverflow.com/questions/3782799/recursively-compose-linq-predicates-into-a-single-predicate, is similar to this but I actually asked the wrong question... the solution there satisfied the question as posed, but isn't actually what I need. They are different, though. Honest.) Given the following search te...

Linq-to-Sql: Update child collection

First table: School (Id, Name) Second table: Student (Id, SchoolId, Name) Suppose I have received updated roster for a school: var school = db.Schools.Single(s => s.Id == updatedSchoolId); school.Students = updatedStudents; db.SubmitChanges(); This does not work, since disconnected students will end up with SchoolId set to null (orph...