linq-to-sql

LINQ 2 SQL, Wrong SQL Generation

Hi, Have a DB table with the structure Id (identity int), Company (string), Cluster (string), BU (string), Department (string),SalesPoint (string) The following Linq Query: var chEntities = from a in dataContext.CompanyHierarchies let parent = (dataContext.CompanyHierarchies.Where(ch => ch.Id == companyHierarchyId).Sin...

LINQ to SQL, Generalization

Hi All, I am struggling a bit to figure this one out. I'm working on an ASP.NET MVC project, using LINQ to SQL for my data layer. The database consists of 10 or so different "exceptions" tables, e.g. "Exceptions.LADM", "Exceptions.USB", "Exceptions.GPO". Basically these tables are tracking user+machine information for relaxation of va...

Creating lightweight Linq2Sql proxy objects

I'm trying to find the most efficient way to send my Linq2Sql objects to my jQuery plugins via JSON, preferably without additional code for each class. The EntitySets are the main issue as they cause not only recursion, but when recursion is ignored (using JSON.NET's ReferenceLoopHandling feature) a silly amount of data can be retrieved...

Why is my WPF Treeview bound to LinqToSql classes being a memory hog?

I have a WPF App which is grinding to a halt after running out of memory... It is basically a TreeView displaying nodes, which are instances of Linq To Sql OR Generated class ICTemplates.Segment. There around 20 tables indirectly linked via associations to this class in the OR designer. <TreeView Grid.Column="0" x:Name="tvwSegments" ...

How do you manage hundreds of "shapes" with a LINQ-based model

Hi All, I have a relatively modest dataset (probably 20 main tables) but it's queried a lot of different ways. Sometimes we show a product. Sometimes a product with it's picture. Sometimes a product with it's picture and comments. Sometimes a product with it's picture and all of the users that have the product and their pictures. ...

Running out of DB connections using LINQ to SQL

In developing a relatively simple web service, that takes the data provided by a post and records it in a database table, we're getting this error: Exception caught: The remote server returned an error: (500) Internal Server Er or. Stack trace: at System.Net.HttpWebRequest.GetResponse() on some servers, but no others. The ones that ...

LINQ to SQL: Mapping a subset of an association

During our initial development we haven't worried about scaling concerns, just getting the bare bones of the system working as a cohesive whole. We are now looking at refining screens where the quantity of records will become too large to be displayed. For example, we have page for displaying the details of a Parent which currently invo...

In LINQ-to-SQL how do I save my object back into my database?

With LINQ-to-SQL in a ASP.NET MVC website I can display objects (records) from my database table. Now I would like to create a new object and save it back to the database. In my Controller, I do this: var dataContext = new MessageDataContext(); Message message = new Message(); message.Action = "save"; message.Body = "r...

Performance benefit when SQL query is limited vs calling entire row?

How much of a performance benefit is there by selecting only required field in query instead of querying the entire row? For example, if I have a row of 10 fields but only need 5 fields in the display, is it worth querying only those 5? what is the performance benefit with this limitation vs the risk of having to go back and add fields i...

Linq to SQL: Is it better to have a small DataContext for each page or a global one?

I am trying out Linq to SQL in an ASP.NET application that uses a large database with lots of foreign keys (100+ tables). I am impressed with how Linq permits you to create a datacontext with all of your relationships intact and to then create Linq statements that automatically join tables. However, this leads to a question: if I am su...

Problem with Linq2Sql Many-to-Many relationship & Inserting new objects.

Hi folks, i'm trying to do a simple linq 2 sql many-to-many, insert some data, operation. here's the stock Northwind model representing a many to many: Now what i'm trying to do is insert a new order and if the product doesn't exist, then insert that at the same time, within the same transaction. The error i'm getting is: System.Da...

What's the best way to save a one-to-many relationship in Linq2Sql?

Hi folks, I'm trying to figure out the best way to save a simple one-to-many relationship in Linq2Sql. Lets assume we have the following POCO model (pseduo code btw): Person has zero to many Vechicles. class Person { IList<Vehicle> Vehicle; } class Vehicle { string Name; string Colour; } Now, when i save a Person, i pa...

Can I start with a string and instantiate an object of that string?

I am currently working with LINQ and C#. I have a DropDownList of the tables in my LINQ to SQL model. I want the user to be able to select a LINQ table name from the DropDown. In code I want to create an instance of that LINQ class and then run a Select or it or anything else I want. How would I accomplish creating the object based on...

Entity Framework query with grouping (many to many)

Hello comrades. I have a classical many to many scenario with three tables (students, courses, and third StudentsCourses assignment table). I'm using EF in my new project and EF designer doesn't create third table. I need to select all cources along with number of students assigned to it. Using plain SQL is very straightforward: selec...

Why am I getting "Invalid Cast" when using Linq to SQL?

I am a bit of a newbie when it comes to Linq to SQL but I hope you can help out. I've written the following Linq to SQL statement with Extension Methods: Cedb.ClassEvents.Where(c => c.ClassID == 1).Select(c => c).Single() Where Cedb is the Datacontext, ClassEvents is a table (for classes and events being held at a facility) and Class...

In LINQ to SQL, how do you pass pass parts of a LINQ query into a function

Is it possible to pass parts of a linq Query into a function? I want create a common interface for my DAL that always uses the same query interface. For example, List<T> Get(Join j, Where w, Select s){ return currentDataContext<T>.Join(j).Where(w).Select(s).ToList(); } Is this sort of thing possible? I'm thinking it wo...

Why does the x.designer.cs part of the LinqToSql dbml triad disappear after an edit in the visual editor?

I ran into a particularly annoying issue. I have a LinqToSql project up and running.. A X.dbml file has three dependent files an X.cs, X.dbml.layout and X.designer.cs Now when I drop an additional table into the designer surface and rename the table, I get an property value is invalid 'unspecified error'. Weird. But then somehow your X....

How to load data from stored linq procedure in combo box?

I have stored procedure in dbml file, I want do smth like this Private Sub GetData() Dim dal = New DataAccess Dim dateList = dal.context.GetAsDateList() Dim enumerator As IEnumerator = dateList.GetEnumerator() While enumerator.MoveNext() cmbDate.Items.Add(enumerator.Current) End While End Sub But I have ...

Linq2sql: Inheritance and associations

I need to create a db structure where "Supplier" inherits from "Client". I used to have an association on Client that I want to move to Supplier, but I can figure out how to define this. IN VS When I add an association to Supplier I can only associate the fields explicitly defined in Supplier (And I need to associate Client.Id). Can I u...

linq to sql case query

Im having problems building a query with the linq to sql data query expression in c#. What I'm trying to ultimately do is based on this pseudo-code expression. public IQueryable<CTest> searchRecords(string category, string searchString, DateTime startDate, DateTime endDate, int searchType, int searchType2) { //-Sear...