linq-to-sql

how can I see the inputs to a LINQ query?

I've got a LINQ query that looks like this (at the end): var query = from myTable0 ... where myTable1.attributeId == 123 && (bunchaStrings.Contains(myTable1.attributeName)) && myTable2.yesNoValue == 'Y' When I see the query it turns into this SELECT ... FROM ... INNER JOIN ... WHERE ... AND (UNICODE([t3].[yesNoValue]) = @p3 So what'...

ValidationAttribute to ensure property value is unique.

See Ref to: http://stackoverflow.com/questions/858987/trying-to-get-generic-when-generic-is-not-available I am trying to write a ValidationAttribute that will ensure that a property value is uniqure: [UniqueValueValidationAttribute] object SomeProperty {get; set;} The attribute knows (or can determine by reflection): The class (Ta...

webform linq to sql and repository pattern sample project

can anyone provide a webform linq to sql and repository pattern sample project link ...

inserting extra data in linq to sql partial class

I have a L2S generated class called Accounts, I have a L2S class called UsersInAccounts I need to add a function call AddUserToAccount(accountid, userid) should/could this function be added to the partial Accounts class I have created or are partial classes used for getting data rather than editing data public partial class Account ...

Linq ExecuteCommand doesn't understand nulls

I'm having a problem when passing nulls to a ExecuteCommand() method using linq. My code is similar to the one that follows: public void InsertCostumer(string name, int age, string address) { List<object> myList = new List<object>(); myList.Add(name); myList.Add(age); myList.Add(address); ...

ValidationAttribute Redux.

Ref to:Creating a ValidationAttribute to ensure unique column values. Ok... Let's try reframing the question: from here I have ripped this code: static TEntity Get<TEntity, TKey>(this DataContext ctx, TKey key) where TEntity : class { var table = ctx.GetTable<TEntity>(); var pkProp = (from member in ctx.Mapping...

C#, Linq2SQL: How long should CommandTimeout be and where should it be set?

We are using C# and Linq2SQL to get data from a database for some reports. In some cases this takes a while. More than 30 seconds, which seems to be the default CommandTimeout. So, I guess I have to up the CommandTimeout. But question is, how much? Is it bad to just set it very high? Wouldn't it be bad if a customer was trying to do so...

Implement IDisposable on partial LINQ to SQL entity classes

I am extending LINQ to SQL entity classes using partial classes, and I'm wondering how to best reset some properties on the entity objects to their default state. My partial classes uses no unmanaged recourses. And as far as I can tell; neither does the LINQ to SQL entity classes. So I'm thinking that I'll implement IDisposable and hand...

Primary Key count Count in LINQ very slow

I thought LINQ to SQL was tuned for performance? The following LINQ to SQL for counting is very poor Dim uniqueFactors As Integer = db.LargeTable.Distinct.Count produces: SELECT COUNT(*) AS [value] FROM [dbo].[LargeTable] AS [t0] WHERE ([t0].[ID] % @p0) = @p1 How every the fastest way to count the number of records based on a prim...

SQL Server: Event does not reference any tables (Tuning Advisor warning)

I have an application written in C# which uses Linq2SQL for communicating with the SQL Server. There are some queries that run a bit (very) slow, and I figure it probably need some indexes to speed things up. But I don't really know how to do that or on what or where or what I should or should not do. So I was thinking I could ask here,...

Is it possible to return IEnumerable of anonymous objects from DataContext.ExecuteQuery?

I develop a reporting engine where reports are based on templates. Every template has string with SQL query and every report has specific values for SQL query parameters. To render a report I set parameters and call DataContext.ExecuteQuery method to get list of records. But to catch returned columns I have to know their names and have a...

How to refactor multiple similar Linq queries?

Suppose I have the two following Linq queries I want to refactor: var someValue1 = 0; var someValue2= 0; var query1 = db.TableAs.Where( a => a.TableBs.Count() > someValue1 ) .Take( 10 ); var query2 = db.TableAs.Where( a => a.TableBs.First().item1 == someValue2) .Take( 10 ); Note that only the Where ...

How do I see common Items between 2 array of Objects

How do I see common Items between 2 array of Objects. My intersect is not returning anything. The object is created from a Linq to SQL class. ...

Flatten One-to-Many Relationship Using Dynamic LINQ

Is it possible to flatten a one-to-many relationship using dynamic LINQ? For example, I might have a list of Users and the User class contains a list of many UserPreferences. The UserPreference class is essentially a name/value pair. A user will define what types of user preferences are available for a group of users. public class U...

How to refactor multiple similar Linq-To-Sql queries?

Read before downvoting or closing: This almost exact duplicate of a previous question of mine exists with the solely purpose to rephrase the previous question to the Linq-To-Sql scope. All answers contained in the previous question are valid for the Linq scope, but are invalid in the Linq-To-SQL scope. Suppose I have the two following L...

Entity - Linq to Sql Only load a part of the entity

If I use entity framework with linq to sql to query it and I have an object Person but I only need two properties of that object, what's in memory will be load, the entire object ? Example : I got the entity Person with properties : Name, Age, Address, Country, Language ... I only need to use the property Name and Age. So I got no ne...

Lost FK relationship with LINQ-SQL designer

I have three tables in my DB (actually a few more than that) these are: Users ----------- ID (PK) Name Sites ----------- ID (PK) SiteName Users_Sites ----------- ID (PK) UserID (FK to Users.ID) SiteID (FK to Sites.ID) and I have a unique constraint on UserID and SiteID in the Users_Sites table. All very standard stuff. My...

linq to sql group by having

Could any one show my how to write query using linq to sql to search for suburbs which have at least 1 venue in specific state Location SuburbID SuburbName StateName Venue VenueID VenueName SuburbName StateName ...

Maximum 'Units of Work' in one page request ?

Its not One is it? I have a method that gets five Lists from different repositories. Each call opens and closes a new Datacontext. Is this ok to do or should I wrap everything in One datacontext. In this case it is not straightforward to use the same datacontext, but i am afraid that opening and closing numerous datacontext in one page ...

Finding the 'Most Improved' in linq

The following code is what i used to identify the Top 10 earning items var top = (from m in db.Stats where m.Item.AccountID == AccountID && m.DateTime >= month && m.DateTime < month.AddMonths(1) group m by m.Item into g orderby g.Sum(p => p.Earnings) descending select g.K...