linq-to-sql

ASP.NET MVC - Passing Grouped data into a View

I've got a LINQ to SQL object, and I want to group the selected data and then pass it into a view. What's the correct way of doing this? I'm sure I need to group the data when I select it rather than grouping it in the view, as this will result in about 200 rather 50000 rows I need to pass into my view. Are there any good examples of ...

How to store multiple database columns into an array with Linq2Sql

I have to work with multiple SQL Server tables that generally look like this: int id_this, int id_that, ..., double Value1, double Value2, ..., double Value96 I know this sucks, but I can't change it. What I want to do now is to define some class like public class Foo { public int Id_This { get; set; } public int Id_That { ge...

Is it possible to change the pluralized name of a LINQ table?

For example, my table name is "Diagnosis". When I bring it into my LINQ to SQL model, it tries to figure out how to pluralize it, and it mistakenly assumes the entity name should be "Diagnosi" and the set name should be "Diagnosis", which could be confusing. When I change the entity name to "Diagnosis" in the properties, it doesn't chan...

T4 Toolbox Linq to SQL Model: Association null after WCF call

I'm using the T4 toolbox Linq to SQL generator, and after making a WCF call, the association properties on my object are null and throwing a null reference exception in their setters. This is one such property: [DataMember(Order = 4, EmitDefaultValue = false)] [Association(Name = "Family_FamilyConfiguration", Storage = "familyConfigurat...

All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists

Hi, I have a linq to sql query where I have to perform union two set of records. And I do not have equal number of fields, so added the null eg my psuedo code is var Values=( from c in containers some joins select new PValues { regionid=r.regionid, roomid=r.roomid, floorid=r.floorid, ma...

LINQ method with varying parameters

I have a LINQ method for the Search page of an in house app. The method looks as below public static DataTable SearchForPerson(String FirstName, String MiddleName, String LastName, String SSN, DateTime? BirthDate) { var persons = (from person in context.tblPersons where person.LastName == LastNam...

Linq to Sql problem

Hello: I am teaching myself Linq to Sql in C#. Because I am using a SqlCE database I had to use SqlMetal to generate the dbml file. This went fine, and I added the dbml file to my program. I can't find out how to generate a DataContext for the database, but I can query the database, but can not insert a row. Here is an example of what do...

Linq to SQL (views or tables)?

I initially thought that using a view would be the best option because I've already encapsulated every column that I want in it. However, after closer inspection, it seems that adding just tables (and using the built-in relationships that are already created) is a much cooler way to do it because those relationships cause LINQ to SQL t...

Linq to Sql Update not persisting to the Database

I have a standard update happening via linq to sql but the data does not persist to the database. I am using an auto-generated class via the .dbml file designer. The update statement is below: public static void UpdateEmailsInWorkingTable(Guid emailGuid, string modifiedEmail) { using (EmailDBDataContext DBContext = new Emai...

Linq2Sql Submit changes does nothing on update

Hi, I am using Linq2Sql and trying to update a table. But no update happens when I try to update a column. I have tried it with the attach statement but then I get a duplicate key error. I am using my own entity and copying it over to the context entity as you can see. Is that my problem? This is my save method. public void Sav...

LINQ to SQL: If database return no values Count() throws an exception

I have a linq to sql statement which returns a set of Customer details to a customer object var customers = from ..... I then use if(customers.Count() > 0) { return customers.First(); } else { return null; } but customers.Count() throws a 'customers.Count()' threw an exception of type 'System.NotSupportedException' int ...

Extract sql query from LINQ expressions.

Is it possible to extract sql statements from LINQ queries ? Say, I have this LINQ expression. string[] names = new string[] { "Jon Skeet", "Marc Gravell", "tvanfosson", "cletus", "Greg Hewgill", "JaredPar" }; var results = from name in names where name.Star...

Can I extend a EntityCollection<Class> : LINQ to SQL

Can I extend or use partial classes to add more functions to EntityCollection< Class> eg. this is the auto-generated classses from LINQ to SQL customer.Orders I want to be able to do customer.Orders.FindByOrderID(orderID) but Order is EntityCollection < Order > Can I make this a partial class or extend it like I can do with just...

Refering to other entities when using Linq2Sql and Sprocs

We are evaluation Linq2Sql for internal applications, and our development guidelines mean that we must always use stored procedures for all CRUD operations, from various blogs i have got together an application that does much of what we want. However, what i would like to do is when we have a relationship between two entities the relati...

Slow response when querying a View - Using Linq to SQL

I have the following view: SELECT poHeader.No_ AS PONumber, poHeader.[Buy-from Vendor No_] AS VendorNumber, poHeader.[Document Date] AS DocumentDate, vendor.Name AS VendorName, vendor.Contact AS VendorContact, vendor.[E-Mail] AS VendorEmail, vendor.Address AS VendorAddress, vendor.[Address 2] AS VendorAddress2, vendor.City ...

Linq - Convert VB.Net to C# help with on query

We're slowly converting some code from VB.Net to C#, so I'm trying to learn the correct syntax in C#. Could someone help with this conversion? Basically I pull from a view all values that have not already been selected (saved) in another table and do a search on the items. Employees a,b,c,d are in the Employee table. I have already sele...

How do I share a data context across various model repositories in ASP.NET MVC using linq2sql

I have a 2 repositories in my application each with their own datacontext objects. The end result has me attempting to attach an object retrieved from one repository to an object retrieved from a different repository which results in an exception. ...

Linq2Sql Updates

Wondering if anyone else has done most of their Update SQL using stored procedures over Linq2Sql? I like Linq2Sql for all the other operations but Updates seem to be nasty. The generated SQL doesn't look good in profiler with all the columns in the Where clause, then you have to select the current object to set the fields from the edited...

A general validation attribute for checking uniqueness in a linq to sql data context

I've been programming asp.net for, oh, a couple of days now. Here's a question I can't even begin to figure out for myself. I hope it's obvious from the code what I want to accomplish, and I have, but it's not pretty. Furthermore I'd like to use it on whatever table, whatever field, i.e. check the uniqueness of a value against a table ...

Serialize generated class from LINQ to SQL

How do i automatically serialize classes that are generated by the mapping of LINQ to SQL? I need to use these objects in WCF. .NET 3.5 SP1. ...