linq-to-sql

Linq to SQL connections

I'm using Linq to SQL for a fairly complicated site, and after go live we've had a number of database timeouts. The first thing I noticed was there are a fairly large number of connections to the database. Coming from an ADO.net background we used to code it so that any site would only use one or two pooled connections, and this resulte...

Is LinqToSQL powerful enough? Isn't a more powerful but equally fluent interface easy to construct?

In a previous question, I asked whether ORM libraries were suboptimal solutions and received a lot of great feedback. As I've thought about the issue further, I've concluded that the primary benefit of LinqToSQL (now) and the promise of LinqToEntities (down the road) lies in their ability to reduce the "mismatch" between procedural code...

linqToSql related table not delay loading properly. Not populating at all.

I have a couple of tables with similar relationship structure to the standard Order, OrderLine tables. When creating a data context, it gives the Order class an OrderLines property that should be populated with OrderLine objects for that particular Order object. Sure, by default it will delay load the stuff in the OrderLine property but ...

Linq to SQL .Sum() without group ... into

I have something like this: var itemsInCart = from o in db.OrderLineItems where o.OrderId == currentOrder.OrderId select new { o.OrderLineItemId, ..., ..., o.WishListItem.Price} is there any way to do a itemsCart.Sum() //not sure what to pass into the function to get the sum of o.WishListItem.Pr...

LINQ to SQL inserting large object from .NET

What is the fastest way to get a list object with a count of 100,000 records into SQL using LINQ to SQL? ...

Pattern name for projecting DAL specific classes (such as LINQ to SQL classes) to POCO's

I was studying the Oxite project on Codeplex. It has repository interfaces, and an implementation using LINQ to SQL. The LINQ to SQL results are projected to POCO objects in the repository implementations. It looks something like: public IQueryable<Post> GetPosts() { return projectPosts(excludeNotYetPublished(getPostsQuery(siteID)))...

Can't access entity from within the View

I'm passing IList<Post> to View(posts). Post is a linqToSql generated model class. Post has an FK relation to the Category table by Id. When I'm iterating over IList<Post> inside my View and trying to access post.Category.Title I'm receiving an error: System.ObjectDisposedException: Cannot access a disposed object. Object name: 'D...

LINQ to SQL - Problem with 1-to-1 association

In the L2S designer I have dropped a table and a view. I tried adding an association between the 2 on their primary keys. This should be a one-to-one relationship, so I set the cardinality property of the association as such. But, when coding I can't access the child property. Any suggestions? EditI just created a view in sql server ...

Linq2SQl eager load with multiple DataLoadOptions

I like to fetch the data with eager-loading using Linq2SQL. The code is similar as : DataLoadOptions options = new DataLoadOptions(); options.LoadWith<Product>(c => c.ProductCompanies); options.LoadWith<Product>(c => c.OrderDetails); db.LoadOptions = options; IEnumerable<Product> products = db.Prod...

Linq - Add Row to results for display only

I have a linq query that returns a brief order summary - product description and product price that gets bound to a data control. I want to add a row to be bound in this same control that displays tax information. The product description column would simply say "Tax" and the product price column would give a tax amount. I used to re...

ComboBox Filling with LINQ C#

Hi , I got a linq based windows project.There is a form thats saving personel's departmant , title , name surname etc..In this form there is 2 combobox item that holding title and departman objects and 1 textbox , 1 listbox.When forms loads i filled listbox with Personel Class.When listbox's selected index change event occur i wanna fil...

Is it beneficial to use multicolumn (composite) primary keys when using Linq to SQL?

Is it beneficial to use multicolumn (composite) primary keys for a many to many relationship table when using Linq to SQL? Or should I just add an identity column as a non-clustered primary key and index the FK columns appropriately? ...

Where is best place to store ObjectContext instance?

I using extension for Object, because it provides very short accessible string. public static BusinessLayer.Models.SearchEngineEntities db(this object o) { if (HttpContext.Current == null) return new BusinessLayer.Models.SearchEngineEntities(ConfigurationManager.ConnectionStrings["SearchEngineEntities"].ConnectionString); if (...

How to pass a Nullable<int> into a stored procedure... from F#?

I'm trying to call a stored procedure with an output parameter from F#, so I need to pass an int? value initialized to null. However, F# is resisting my attempts, saying that the object cannot be null. I've read up on the web as to why that is but my problem remains - I need to call that stored procedure. Has anyone got any ideas as to h...

Random row from Linq to Sql

What is the best (and fastest) way to retreive a random row using Linq to SQL when I have a condition, e.g. some field must be true ? ...

How can I get a percentage of Linq-to-SQL submitchanges?

Hi, I wonder if anyone else has asked a similar question. Basically, I have a huge tree I'm building up in RAM using Linq objects, and then I dump it all in one go using DataContext.SubmitChanges(). It works, but I can't find how to give the user a sort of visual indication of how far has the query progressed so far. If I could ultimat...

C# DTO AND LINQ2SQL

Hi everyboy! This is my first question, be gentle :). Im working on a project with some kind of distributed architecture.Im trying to do the following: I have a Data Access Layer that uses LINQ2SQL I have a Service Layer that is a proxy for the Data Access Layer. I have a Business Layer that calls the Service Layer for Entities. The ...

Common problem for me in C#, is my solution good, stupid, reasonable? (Advanced Beginner)

Ok, understand that I come from Cold Fusion so I tend to think of things in a CF sort of way, and C# and CF are as different as can be in general approach. So the problem is: I want to pull a "table" (thats how I think of it) of data from a SQL database via LINQ and then I want to do some computations on it in memory. This "table" conta...

What is the fastest way to determine if a row exists using Linq to SQL?

I am not interested in the contents of a row, I just want to know if a row exists. The Name column is a primary key, so there will either be 0 or 1 matching rows. Currently, I am using: if ((from u in dc.Users where u.Name == name select u).Count() > 0) // row exists else // row doesn't exist While the above works, it does a l...

Advanced Search in Linq to SQL possible??

Without the use of "LIKE" in Dynamic Linq it virtually renders it useless to me when trying to create an advanced search query. How have any of you overcome this Advanced Search problem when using Linq to SQL? I'd need to search the following field types and they all could be null as well: List item varchar (column LIKE '%' + myText ...