linq-to-sql

Can you use LINQ tools such as SQLMetal with an access database?

I'm creating a small database application to teach myself the following concepts C# programming .Net 3.5 framework WPF LINQ ORM I want to use Microsoft Access as the database but I can't seem to find any mention of whether its possible to use SQLMetal to generate the ORM code from a Microsoft Access database. Does anyone know if thi...

Is there a pattern using Linq to dynamically create a filter?

Is there a pattern using Linq to dynamically create a filter? I have the need to create custom filtering on a list, in the past I would just dynamically create the SQL...it doesn't seem like this is possible with Linq. ...

Best use pattern for a DataContext

What's the best lifetime model for a DataContext? Should I just create a new one whenever I need it (aka, function level), should I keep one available in each class that would use it (class level), or should I create a static class with a static DataContext (app-domain level)? Are there any considered best practices on this? ...

Best Practices for Managing Linq to SQL Dbml Files?

I've just started using Linq to SQL, and I'm wondering if anyone has any best practices they can share for managing dbml files. How do you keep them up to date with the database? Do you have a single dbml file for the entire database, or is it split into multiple logical units? How does managing this file work in a team environment? ...

What is the syntax for an inner join in linq to sql?

I'm writing a linq to sql statement & I'm just after the standard syntax for a normal inner join with an 'on' clause in C#. ie how do you represent this in LINQ to SQL?: select * from table1 inner join table2 on table1.field table2.field EDIT: Real query to get all contacts for a dealer: select DealerContact.* from Dealer inne...

How do you implement caching in Linq to SQL?

We've just started using LINQ to SQL at work for our DAL & we haven't really come up with a standard for out caching model. Previously we had being using a base 'DAL' class that implemented a cache manager property that all our DAL classes inherited from, but now we don't have that. I'm wondering if anyone has come up with a 'standard'...

How can you easily reorder columns in LINQ to SQL designer?

When designing LINQ classes using the LINQ to SQL designer I've sometimes needed to reorder the classes for the purposes of having the resultant columns in a DataGridView appear in a different order. Unfortunately this seems to be exceedingly difficult; you need to cut and paste properties about, or delete them and re-insert them manuall...

How to use LINQ To SQL in an N-Tier Solution?

Now that LINQ to SQL is a little more mature, I'd like to know of any techniques people are using to create an n-tiered solution using the technology, because it does not seem that obvious to me. ...

Best way to update LINQ to SQL classes after database schema change

I'm using LINQ to SQL classes in a project where the database design is still in a bit of flux. Is there an easy way of synchronising the classes with the schema, or do I need to manually update the classes if a table design changes? ...

Managing LINQ to SQL .dbml model complexity

This question is addressed to a degree in this question on LINQ to SQL .dbml best practices, but I am not sure how to add to a question. One of our applications uses LINQ to SQL and we have currently have one .dbml file for the entire database which is becoming difficult to manage. We are looking at refactoring it a bit into separate f...

LINQ to SQL for self-referencing tables?

Let's see if I can describe this well... Say, I have a self referencing Categories table. Each Category has a CategoryID, ParentCategoryID, CategoryName, etc. And each category can have any number of sub categories, and each of those sub categories can have any number of sub categories, and so and and so forth. So basically the tree can...

What can I do to resolve a "Row not found or changed" Exception in LINQ to SQL on a SQL Server Compact Edition Database?

When executing SubmitChanges to the DataContext after updating a couple properties with a LINQ to SQL connection (against SQL Server Compact Edition) I get a "Row not found or changed." ChangeConflictException. var ctx = new Data.MobileServerDataDataContext(Common.DatabasePath); var deviceSessionRecord = ctx.Sessions.First(sess => sess....

LINQ to SQL Association - "Properties do not have matching types"

Hi, I am trying to link two fields of a given table to the same field in another table. I have done this before so I can't work out what is wrong this time. Anyway: Table1 - Id (Primary) - FK-Table2a (Nullable, foreign key relationship in DB to Table2.Id) - FK-Table2b (Nullable, foreign key relationship in DB to Table2.Id) Table2 - I...

How do I write SELECT FROM myTable WHERE id IN (SELECT...) in Linq?

How do you rewrite this in Linq? SELECT Id, Name FROM TableA WHERE TableA.Id IN (SELECT xx from TableB INNER JOIN Table C....) So in plain english, I want to select Id and Name from TableA where TableA's Id is in a result set from a second query. ...

Best practices re: LINQ To SQL for data access

Part of the web application I'm working on is an area displaying messages from management to 1...n users. I have a DataAccess project that contains the LINQ to SQL classes, and a website project that is the UI. My database looks like this: User -> MessageDetail <- Message <- MessageCategory MessageDetail is a join table that also conta...

Deploying a project using LINQ to SQL

I am working on a winforms application using LINQ to SQL - and am building the app using a SQL Express instance on my workstation. The final installation of the project will be on a proper SQL Server 2005. The database has the same name, and all tables are identical but the hostname is different. The only way I have found to make my...

LINQ and Database Permissions

I'm still trying to get my head around LINQ and accessing a SQL Database. I was always taught that you should only have execute permissions of stored procedures to your data. You should never have select / insert / update / delete. (This is because of performance and security) To get the data out of LINQ you obviously need select per...

Optimizing a LINQ to SQL query.

I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount) { DatabaseDataContext db = new DatabaseDataContext(); return (from o in db.Orders orderby o.CreatedDate descending select o) .Skip(pageIndex * recordCount) .Take(recordCount) .ToList(); } I need to print the infor...

What is a reason that LINQ to SQL wouldn't generate a collection based on a relationship?

I have a relationship between two entities (e1 and e2) and e1 has a collection of e2, however I have a similar relationship set up between (e2 and e3), yet e2 does not contain a collection of e3's, any reason why this would happen? Anything I can post to make this easier to figure out? Edit: I just noticed that the relationship between ...

How can you handle an IN sub-query with LINQ to SQL?

I'm a bit stuck on this. Basically I want to do something like the following SQL query in LINQ to SQL: SELECT f.* FROM Foo f WHERE f.FooId IN ( SELECT fb.FooId FROM FooBar fb WHERE fb.BarId = 1000 ) Any help would be gratefully received. Thanks. ...