linq-to-sql

Force LINQ to SQL getting data just one time

I'm using linq to sql. And do something like: IEnumerable<VarValues> parameters = GetDayParameters(); protected IEnumerable<VarValues> GetDayParameters() { return "some linq query"; } After that, i'm using LINQ to Objects for "parameters"-variable, in loop, and that queries start to connect to database. Question is, can i force L...

How do I stop SQL Server 2008 R2 trying to install some package when I build my setup project?

I have a WPF Linq-to-SQL project which I have been developing using MS Visual Studio 2008. I was running SQL Server 2008, and recently upgraded it to version R2. Now, whenever I build my SETUP project (not the app itself), the build process causes a window to launch: SQL Server 2008 R2 Management Studio Please wait while Windows configu...

linq to sql continue error

i had an error on a linq query when i tried to do SubmitChanges() the problem is that what ever i try to do in my project now i'm getting the same error (i guess the linq still tring to do the Error Change) how can i clean the pendding changes or deal with that issue otherwise? Thanx! ...

Linq-to-sql logic pain

I've been trying to get the following method cleaned up using more sensible and lean syntax, but I'm striking serious headaches when it comes to aggregate clauses and filtering using L2S. Particularly, I feel I should be able to use a .Contains() method to filter out objects whose tags fit the string parameter passed in the method, but ...

How to access property of generic type in linq expression

Iam using .NET 3.5. I have asp.net mvc app. There is base controller: public abstract class BackendController<TModel> : BaseController where TModel : class { // skipped ... public ActionResult BatchDelete(int[] ids) { var entities = repository.GetList().Where(item => ids.Contains(item.ID)); repository.delete(entities) } ...

LINQ how to query if a value is between a list of ranges?

Let's say I have a Person record in a database, and there's an Age field for the person. Now I have a page that allows me to filter for people in certain age ranges. For example, I can choose multiple range selections, such as "0-10", "11-20", "31-40". So in this case, I'd get back a list of people between 0 and 20, as well as 30 to 4...

Subsonic3 and ASP.NET MVC: Is there something like DataContext.GetTable<T>?

Right now I'm working my way thru the SportsStore exercise of Sanderson's "Pro ASP.Net MVC 2 Framework" book (page 107) and the exercise has me implementing a Repository pattern backed by a DB store using LINQ-to-SQL. I'm trying to figure out how to implement this same repository with the Subsonic ORM. The basic repository code is as fo...

How to sort DBML objects alphabetically?

I've got a DBML file in my project with all my LinqToSql objects. Initially I imported them from the DB, and all was well. Now as my DB has been growing, I've been adding the new tables to the diagram in the O/R Designer, but they always get appended to the end of the XML. This is a bit of a pain, because when I'm defining foreign key...

Linq-To-SQL Table Class Design

I'm using Linq-To-SQL for a project with around 75 tables. We have to keep a cache of entire tables that we pull down because the entities are all interrelated and pulling them on demand takes way too long. So, to track all of these entities from all of these tables, we have a single class responsible for maintaining in-memory table refe...

Multiple search parameters with LINQ

I'm writing what I believe should be a relatively straight-forward Windows Form app. I'm using LINQ to SQL, though I have never used it before. We have a SQL Server database, and I'm creating a front-end to access that database. I'm trying to figure out the most efficient way to search for multiple (arbitrary number of) search parameters...

LINQ to SQL query help

Hi -I have 2 entities -Offer and Share. Share stores the offers shared by users. class Offer int IDOffer; bool Shared; (other properties) class Share int IDOffer; int IDUser; where Offer.IDOffer = Share.IDOffer, 1-to-1 (users may share an offer only once, or not at all). I extended Offer with the Shared property ...

What is the best way to write code that first checks if a row exists and updates or inserts it accordingly?

I am rather new to the more modern ways of coding database persistence, and my intuition is telling me I probably am missing something because my code seems "inelegant" but I do not see another way to do it. Note: I understand maybe Linq to SQL is considered "dead". I'm more in a "learning the concepts" mode assuming that I can probabl...

Consolidate or reuse LINQ expression

I have a LINQ expression that gets used as a filer in a LINQ to SQL statement where clause. My problem is that the LINQ to SQL expression has become unwieldy and also the logic it contains has ended up in multiple locations violating DRY (this is the 3rd time I'm working on a bug raised by QA for it getting out of sync). Is there any wa...

best practice for avoid connection timeout when using LINQ to SQL

i need to know best practice for avoid connection timeout when using LINQ to SQL in .net applications specially when returning IQueryable<T>from data access tiers or layers. I get "Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in us...

Creating a queryable property for a linq to sql entity

I have a simple table structure in SQL Server: One table storing a list of Bikes (Bikes) and a second table storing a historical list of the bike's owners (Owners). Using Linq 2 SQL I generated a model that gives me a 'Bike' entity with a 1 to many relationship to 'Owner' called 'HistoricalOwners'. So far so good... Now I have many q...

Entity Framework 4 vs LINQ to SQL, for small or medium-size apps, working with SQL Server

I've seen some discussion about L2S vs EF4 on Stack Overflow back in April, when VS2010 was launched, namely: Dump Linq-To-Sql now that Entity Framework 4.0 has been released? Is Entity Framework worth moving to for a new small app? Now, after 6 months, presumably people have had more interacting with EF4, so I'm curious of fresh opin...

LIKE in OData query

I am converting a project from using linq2sql to use an odata source. I am trying to lookup a user like this... FrameworkEntities db = new FrameworkEntities( new Uri("http://localhost/odata/FrameworkService.svc")); User user = db.Users.Where( u => SqlMethods.Like(u.UserName, UserName)).FirstOrDefault(); but am getting the erro...

Should I use the entity framework or linq to sql for new mvc project?

I have a new project where I want to use MVC (I will be learning as I code), and I have never used linq or entity (or mvc). Which should I use? Does it matter? edit: I will be having a lot of different databases, from Oracle to FoxPro. ...

parsing Hierarchical self-join table by tree level?!

Hi friends, I have a self referential category table as you see: I want to parse this table to find out tree level for each category. for example if root node level is 0 then CPU and Hard Drive and VGA and RAM are in level 1 and so on. how can I handle that? I created a dictionary to put each category ID and its Level: Dictionary<int...

Replace a database MDF file with backup file during runtime in C#

I've written quite a long C# program using Linq to Sql and my data are stored in an MDF file located near my program's EXE. A part of my program has a form for backing up the database files simply by copying the MDF and LDF files into a user-specified folder. However if I query the database and then try to replace the original files wit...