linq-to-sql

LINQ to SQL - Partial class to selectively change shape

What I have: LINQ to SQL auto generated class, which corresponds to the shape of its SQL table. TABLEA ======== column1 column2 What I want to do: Extend TABLEA class to include a new property, whose related column will be present only when a particular stored procedure is called. The stored procedure return type will be of TABLEA....

How do I get something similar to the SERIAL PG datatype in SQL Server 2008?

I'm helping implement a SQL Server 2008 database and I have several columns that I'd like to default to the next number in a sequence, but still be able to insert numbers by hand into it at will. In PostgreSQL this is done with the SERIAL datatype and a sequence. Unfortunately those things do not exist in SQL Server. Here's what I know W...

Linq to SQL and Collection operations

I have a Dictionary which I'd like to use like an IN clause within a SQL query. I have a Linq-To-SQL query where I would like to use this Dictionary's Keys to check fields in the rows for the query. E.g. bool result = DataContext.Table.Any(res => MyDictionary.ContainsKey(res.field1)); In effect this is similar to exists(sel...

Linq to SQL catch OnChanged "event" for entity association change

Lets say I have a couple Linq to SQL classes, Person and Department. Person has a entity association to Department. I can catch a change to Person.Name using OnNameChanging and OnNameChanged in the partial class but the designer generated code doesn't seem to call OnDepartmentChanging or OnDepartmentChanged. How can I catch these kind...

Can you prevent LinqDataSource from setting a property?

I've got a Linq 2 SQL object I'm trying to update. Two of the properties on this object are related to each other, and setting one sets the other. So if I do: Foo.Code = BEER; The Foo.CodeID property will automatically be set to 5 (or whatever.) The problem is that LinqDataSource sets Foo.Code, then immediately sets Foo.CodeID... wh...

LinqToSQl and the Member access not legal on type exception

The basic problem... I have a method which executes the following code: IList<Gig> gigs = GetGigs().WithArtist(artistId).ToList(); The GetGigs() method gets Gigs from my database via LinqToSql... So, when GetGigs().WithArtist(artistId).ToList() is executed I get the following exception: Member access 'ListenTo.Shared.DO.Artist Arti...

Is it Possible to set a Default Order By in Linq Attribute Mappings?

I it was possible to do this in Active Record, but is this feasible with Linq to SQL? ...

Entity Framework: Loading Many to One entity

Say I have a role entity and a site entity. Now there are many roles to one site, so on the Role class there is a Site property that represents that relationship. If I wanted the roles for a site I would do this: Site.Roles.Load() Problems is, since the Site property on the Role class isn't a collection but just a single entity, the...

From LINQ to SQL to Entity Framework, what features do you want?

If you're going to be moving from LINQ to SQL to the Entity Framework what features do you most want to see move along with it? What features do you think are requirements to move existing projects? ...

Passing data in ASP.NET MVC using LINQ - nuttiness

Allow me to start with: I am a n00b on ASP.NET MVC. I love it, but I am a n00b. I am trying to pass "complex" data back from a LINQ query. I understand how to use the data context and then just cast that data when I send it back, but when I do a more complicated LINQ query which returns an anonymous type, things break down. I saw som...

Linq2Sql: Detech if entity is attached to a datacontext

I've a procedure where I need to save a entity object. The problem is that I don't know if this entity is attached to my datacontext or not. To solve this I use the following code: try { db.ClientUsers.Attach(clientUser); db.Refresh(RefreshMode.KeepCurrentValues, clientUser); } finally { } db.SubmitC...

SELECT @@DBTS using Linq to SQL

How can I use Linq to SQL to retrieve @@DBTS using C#? Here is what I am trying: IEnumerable<System.Data.Linq.Binary> results = db.ExecuteQuery<System.Data.Linq.Binary>(@"SELECT @@DBTS"); However, this results in "The type 'System.Data.Linq.Binary' must declare a default (parameterless) constructor in order to be constructed during ma...

LINQ to SQL error

I have a form in which I am able to list a parent table using datagridview. I also have a child payment table that list all the payments made. I have added a combo box so I can make my search more efficient. Everythhing worked great until I added to box. Now I get this error== InValidCastException == Conversion from string "" to type 'D...

Equal sign in LINQ

The SQL server doing queries based COLLATE option, so you can define how comparision will be performed (case sensitive or not). You can do it when you creating table or during query execution. How can I control collation during my LINQ to SQL queries? Will my queries be allways case insensitive when I will do table.Column == stringValue...

ASP.NET MVC design

As I've stated before I'm working on a digg clone to teach myself ASP.NET MVC Inside and out but I've hit a road bump that I can't seem to avoid. I want to be able to optimize this application as much as possible so I have my DAL which is a bunch of classes of ...Repository : Repository. Now to help optimize for performance I have my b...

Trying to change properties of an IQueryable collection

I am trying to do what I think is something simple, but I suspect I am simply too n00b to know that I am probably doing something wrong. I have a LINQ query return: IQueryable<CWords> Result Where CWords is a class I defined as follows: public class CWords { public CWords(){} public string _column1{ get; set; } public fl...

How to match a set using Linq-2-Sql

I'm trying to figure out how to do this, and I"m stumped. I'm sure it's something simple that I'm just missing. Say I have a table that is a collection of names, and I want to check if a subset of those names exist like this: var names = new List{ "John", "Steven", "Mary"}; var dbNames = from n in Db.Names where n.FirstNa...

WPF Linq to SQL applications Some Best practices using binding and master/detail views

Hi, Well i feel im missing something here because im having problems i bet a bunch of people ran into before and i cant find any solutions to this simple scenario. Application Technology: WPF, 3.5(sp1) framework, LINQ to SQL, o/r designer CRUD, Visual studio 2008, C#. Apllication Layout: Main layout conatins a panel to the left holdi...

LINQ-to-SQL select filter

Is there a way to ensure a particular conditional clause is added to the expression tree on each select from a particular table? For example, a table with a field with the date a record was deleted should never come back or be included in any kind of statement. Rather than include a where clause each time, is there a way, without cre...

C#: Is ObjectTrackingEnabled = false worth it for small operations?

Given the following piece of code: using(var data = new SomeDataContext(ConnectionString)) { data.ObjectTrackingEnabled = false; foreach(Something in data.Somethings) someList.Add(something.SomeProperty); } Is it worth it setting object tracking to false? I know it is just one line of code, but it kind of bugs me having to w...