linq-to-sql

Problems creating my own Custom DataAttribute for LinqToSql

I'm building LINQ Models by hand, because I want to (understand what's reall happening). There is a great light weight tutorial on turning standard classes into Linq Models I am reading Here. For my sample application I have created some models that look like: public class LoginModel { [Column(IsPrimaryKey=true, DbTyp...

CRUD in Winforms with linq-to-sql

I have a simple winforms application that I am connecting to my database with linq-to-sql. I have generated the classes directly from the database, and I have a DataAccess class that wraps my datacontext and can give me whatever I need. I have a view that uses an object datasource to populate a DataGridView and a set of related text fi...

Avoiding race-condition when manually implementing IDENTITY-like increment for a SQL Server DB column

I'm building an ASP.NET MVC 2 site that uses LINQ to SQL. In one of the places where my site accesses the DB, I think a race condition is possible. DB Architecture Here are some of the columns of the relevant DB table, named Revisions: RevisionID - bigint, IDENTITY, PK PostID - bigint, FK to PK of Posts table EditNumber - int Revis...

Optimizing query and/or data model for calendar app

Our calendar application represents an appointment domain as: Appointment ID (PK) StartDateTime EndDateTime ... AppointmentRole AppointmentID (FK) PersonOrGroupID (FK) /* joins to a person/group, outside the scope of this question */ Role ... Appointment has a 1 to many relationship with AppointmentRoles. Ea...

Link to SQL and class mapping

Hi Experts, I am new to linq and asp.net mvc and right now i am developing a project based on Asp.net mvc using Linq to sql as a data access technology.But i am very confuse about the way of using linq to sql classes.Is it good practice to create a new class for each entity on dbml file and map between them and use that newly created cl...

Disable all lazy loading or force eager loading for a LINQ context

I have a document generator which contains queries for about 200 items at the moment but will likely be upwards of 500 when complete. I've recently noticed that some of the mappings denote lazy loading. This presents a problem for the document generator as it needs access to all of these properties based on which document is being genera...

Databinding with LINQ

Hello, I'm databinding a radiobuttonlist with a LINQ query like so: var query = from m in Db.Udt_Menu orderby m.Name select m; this.radMenuSelection.DataValueField = "menuID"; this.radMenuSelection.DataTextField = "name"; this.radMenuSelection.DataSource = query; this.radMenuSelection.DataBind(); However, when i wa...

How do I get the overload through reflection at runtime?

Hi, Since where I work force me to use stored procedures and I haven't been around long enough to prevent it I have customized LiNQ to SQL code generation for all our stored procedures. Yes that's right we have stored procedures for ALL our data access and since we don't have table access it means that we often end up with 3 classes for...

What are options for passing objects between layers when LINQ to SQL is used?

When thinking about traditional layered application design, I often think in terms of 3 layers: The bottom-most layer which actually talks to the database (let's call this the "data access layer"). It returns objects (in some form) to the next layer. The layer above the bottom-most layer (the middle layer, which I'll term the "data la...

Am I misunderstanding LINQ to SQL .AsEnumerable()?

Consider this code: var query = (from a in db.Table where a = SomeCondition select a.SomeNumber).AsEnumerable(); int recordCount = query.Count(); int totalSomeNumber = query.Sum(); decimal average = query.Average(); Assume "query" takes a very long time to run. I need to get the record count, total SomeNumbe...

Two similar classes, which should do the work?

I've 2 classes. One is a linq-to-sql class and the other is a seriazable data-dump class. Examples: Class TableNotes Id UserId NoteText ... functionality [Serializable] Class NoteDump NoteText ... functionality They both would share a common set of functionality. I decide it is best for me not to duplicate this functionality and th...

Missing constructor in a class derrived from a generic class

I'm trying to create a generic LINQ-TO-SQL repository based on this post which basically lets you define a generic base repository class, then you can define all of your actual repository classes by deriving from the generic base. I want the option of using a repository with or without passing in the data context, so I decided to create...

Why does this query timeout? V2

This question is a followup to This Question The solution, clearing the execution plan cache seemed to work at the time, but i've been running into the same problem over and over again, and clearing the cache no longer seems to help. There must be a deeper problem here. I've discovered that if I remove the .Distinct() from the query, ...

Linq to SQL using Repository Pattern: Object has no supported translation to SQL

I have been scratching my head all morning behind this but still haven't been able to figure out what might be causing this. I have a composite repository object that references two other repositories. I'm trying to instantiate a Model type in my LINQ query (see first code snippet). public class SqlCommunityRepository : ICommunityRepo...

Linq To Sql Nested Select

This is the SQL query I am trying to write with LINQ: SELECT pd.Description, pd.Name, pd.SKU, pt.FileName, (SELECT ISNULL(M1.parent, '') + '/' + M2.parent + '/' + M2.slug FROM seo AS M1 JOIN seo AS M2 ON M1.Slug = M2.Parent WHERE M2.SeoId = pd.seoId) as Url FROM SEO seo INNER JOIN Products p on seo.SeoID = p.SeoID INNER ...

asp.net 4.0 dynamic data generating search or filtering for each columns

Hi, I am using dynamic data entities linq to sql project. For my test project I have one table, with 10 columns and a single primary key for example. Almost all the columns are varchars. I can get the basic project up and running fine - update, delete, insert etc. Since it has no foreign keys, there are no search filters rendered. I w...

Construct nested linq-to-sql expression so as to generate a single SQL query

I'm trying to construct my linq-to-sql expression so that it only generates a single SQL database query. The query involves two nested selects, a simplifed verion is: var query = from person in People where person.ID == 1234 select new PersonDetails() { ID = person.ID, ...

Iterating tables in a context and the properties of those tables

I'm iterating the tables of a context and then the properties of those tables to eager load all columns in a context. I received some help via another question, but I don't seem to be able to figure out how to iterate the column properties of the actual table. Final working code: public static void DisableLazyLoading(this DataContext...

LINQ entities used in models. Can I use OnPropertyChanged, and IEditableObject?

Let's say I have an app and a web site using the same database. I wan't to create a Data layer and some model objects. In many cases the model objects uses alot of info from some of the database tables. My idea was to wrap the LINQ to SQL entity class for the table inside the view so I won't have treate the properties again. I was wonde...

Eagerly loading entities in Linq2Sql

I’m trying to eagerly load an entity and its related properties (basic one to many) using the LoadWith and AssociateWith DataLoadOptions. However, after looking at the generated SQL I noticed that the statements generated by LoadWith are all Left Outer Joins. So the code below generates all left outer joins to fetch the data of the a...