linq-to-sql

How to clear the DataContext cache on Linq to Sql

Hi, I'm using Linq to Sql to query some database, i only use Linq to read data from the DB, and i make changes to it by other means. (This cannot be changed, this is a restriction from the App that we are extending, all updates must go trough its sdk). This is fine, but I'm hitting some cache problems, basically, i query a row using Lin...

Linq, Left Join and Dates...

So my situation is that I have a linq-to-sql model that does not allow dates to be null in one of my tables. This is intended, because the database does not allow nulls in that field. My problem, is that when I try to write a Linq query with this model, I cannot do a left join with that table anymore because the date is not a 'nullable...

Subquery in LINQ that's in the select statement, not the where clause

I need to do something like the following SELECT p.name, (SELECT COUNT(p.id) FROM products WHERE products.parent_id = p.id) AS sub_products FROM products AS p I see lots of LINQ examples of subqueries in the where clause, but nothing like this where it's in the select statement. ...

linq to sql grouping multpile

I want to select 10 names from each of 3 degree for 2 different categories of items: Name Degree (md, phd, bs) Category (orange, green) so i need 10 names md orange, 10 names phd orange,10 names bs orange AND 10 names md Green, 10 names phd Green,10 names bs Green how to write linq statement? ...

LINQ expression works in LinqPad but not C# Silverlight Application

Hello, I have been working with a Linq query in a Silverlight application which returns only the row of a table which contains the max value of the field OptionARMRunId (identity). When executed in LinqPad, the query runs fine and returns the correct row. However, when used in my Silverlight application, the application never moves pas...

LINQ to SQL - is there a way to get a 'preview' of the database with changes made to a context?

I have a program in which I am performing non-atomic updates to the database with a single DataContext (that is, the changes are submitted when the user clicks Save, not after each transaction). When the user saves, I would like to be able to query the database (as it would be when I call submitChanges()) and do some checks just before ...

LINQ TO SQL Mapping Error

Iam using LINQ To SQL with POCO's and XML mapping. I am getting the following error when I try to run the application: Cannot find type 'MyProject.DataTransfer.User' from mapping. Below is the mapping: <Table Name="Users" Member="User"> <Type Name= "MyProject.DataTrasnfer.User"> <Column Name="UserID" Member="UserID" ...

Should I use Linq-to-SQL or the Castle ActiveRecord implementation?

I don't want to write stored procedures any more (not unless I have to), so should I use out of the box Linq-to-SQL or the Castle ActiveRecord implementation? I understand there are some differences between the two as mentioned here on Stackoverflow ...

Help with Error " 'object' does not contain a definition for 'Text' "

Here's the problem: This is for a WPF app that uses C# and LINQ to SQL. When a user wants to look at a list of customers, he/she begins entering the name in a textbox. The textchanged event uses the input text to define the where clause of a LINQ statement that filters the list. I currently have two such text boxes that run essentiall...

why does DefaultIfEmpy throw NotSupportedException?

var defaultRole=ZAssociateRoles.Single(r=>r.RoleName=="Associate"); var allAssociates=(from a in ZAssociates join arm in Associate_role_maps on a.UserName equals arm.UserName into leftArm from la in leftArm.DefaultIfEmpty() join r in ZAssociateRoles on la.AssociateRoleId equals r.AssociateRoleId into leftOuterRole ...

SQL to LINQ converter required, any idea ?

We have LINQPad which is great for testing Linq expressions targeting database. Can any one recommend "free ware" tool, that could help us convert "Sql Queries" to LINQ expressions and why you recommend it? NOTE: Please keep in mind, we use c#. ...

CompiledQuery Error only on very first call

I am trying to use compiled queries for my data access code in an asp.net application. The code I am using for updates is shown below. public void Update(IFoo item) { using (SqlConnection connection = GetConnection()) using(FooDataContext dc = new FooDataContext(connection)) { FooData data = ...

Where to put Model-specific code when using .dbml designer?

I'm building an asp.net mvc application for users to enter an essay contest. I have an Essay table in sql server 2005. I created my domain models by dragging over the tables in the server explorer and saving the layout as, what I've named DAL.dbml. I'm now trying to implement input field validation in the business layer using method...

Updating an ObservableCollection in a separate thread

In a WPF application an ObservableCollection is filled and updated by LINQ to SQL queries. Then UI objects are updated using values from this ObservableCollection. Is it possible and reasonable that operations of updating this ObservableCollection by LINQ to SQL queries were executed in a separate thread? If yes, will, in this case, i...

Linq filter issue involving a varchar(1) field

I have a field in my database that is varchar(1). I'm not permitted to change it. The only values for this field are 0 or 1. Here is the where clause of the linq query: where g.id_Group == idGroup && a.AccountOpen.Value == '1' My linq query generated the following sql where clause WHERE ([t1].[id_Group] = 1234) AND (UNICODE([t0].[A...

Validation Engine....Business Rules.

Hello, subject is... I have a Linq to SQL class that i need to define a "rule engine" before saving it back to the database, this of course involves all foreign keys - associations, common, the whole object graph i created and manipulated, or value changed object from the database. Thing is, i don't have any experience on the subject a...

Can I add a common function to a set of EntitySet<TEntity> Classes - LINQ to SQL

I am using LINQ to SQL and want to add functions to autogenerated EntitySet< TEntity > collections. eg. City.Houses where Houses is automatically generated EntitySet < House > I am using extension method to add extract function to the EntitySet < House > class so that I can get something like City.House.FindByID(id); but now I ...

Can LINQ To SQL generate invalid SQL?

I have two tables that I am using Linq to SQL with. The tables have a 1 to many association. The important part of the database schema is as follows: Camera: Id (int) SerialNumber (string) ... CameraCalibration Id (int) CameraFk (int) ... Using LINQ to SQL I can obtain a list of all Camera Calibrations for cameras with 10...

How does this LINQ Expression work?

I know what this code is doing but I'm not sure on the syntax. It doesn't seem to conform to a "standard" format. Is it mostly LINQ? return db.Subjects.SingleOrDefault(s => s.ID == ID); The first part makes sense but it's the part in the brackets I don't understand. How can we use s without declaring it? And how are we putting logic i...

Linq entity serialization problem

In my project we serialize disconnected Linq-to-sql entities(mainly to preserve them between postbacks). Code in use for that is fairly straightforward: public static string Serialize<P>(this P entity) { StringWriter writer = new StringWriter(); XmlTextWriter xmlWriter = new XmlTextWriter(writer...