linq-to-sql

Catch the error from Stored Procedure in C#

I have a stored procedure that is called to validate a user during login. If success it returns the user entity, and that works good! My question is if it doesn't work, I'll raise an error in the SP, How do I catch this error and use it in the best way? Right now I'm getting nullrefference, this is the code: Store procedure: ALTER PRO...

Can you get DataReader-like streaming using Linq-to-SQL?

I've been using Linq-to-SQL for quite awhile and it works great. However, lately I've been experimenting with using it to pull really large amounts of data and am running across some issues. (Of course, I understand that L2S may not be the right tool for this particular kind of processing, but that's why I'm experimenting - to find its...

ASP.NET - Advanced Where-Clause in LinqDataSource

I have two tables: Orders OrderProducts - An order can have 1 to many orderProducts records associated with it. What I am trying to do (unsuccessfully) is to implement a GridView search using a LinqDataSource wherein the search returns Order results where any of the OrderProduct.Manufacturer columns contain a search query. I was ho...

Adding two entities with FKs pointing to each other

I have two tables in my application. The first one, Sections, stores content for a specific section of an online publication. This contains (among other things) the section title and a field CurrentRevisionId (FK). A second table, Revisions, stores different revisions of that content. It has PK RevisionId field (the FK above, used to...

Stored Procedure with LINQ, how to work with the dynamic return type

When working with stored procedures in linq, I can go to my SP and select what type of entity it should be returning. This works fine in most cases, except the time's I'm not sure of what will be returned. If I don't select what type of entity to return i get the standard return ISingleResult<SP-Name> I thought I would be able to wor...

Quicker way to loop through LINQ data

I am writing code that pulls data from database tables and writes them to an XML file (to be picked up by another process). There are bout 60,000 records, and each record can have multiple entites, i.e. a member can have several contacts, each contact can have several phone numbers, etc. The entire process takes several hours, and I've n...

How can I share same action logic between controllers with respect the repository pattern

I have CompanyController and DepartmentController: public class CompanyController : BaseBackendController { private ICompanyRepository repository; public CompanyController(ICompanyRepository repository) { this.repository = repository; } ... [HttpPost] public ActionResult BatchDelete(long[] ids) { var e...

Generated T-SQL from LINQ to SQL performs DATEPART

The following LINQ to SQL query is splitting the date into pieces. It seems odd that a date comparison would use the following generated SQL statement. var customers = (from c in db.customers where c.servhists.Any(sh => sh.donedate.Value.Date >= startDate.Date && sh.donedate.Value.Date <= endDate.Date &...

Linq to SQL - Group By Table

This doesn't work: Dim Qry = From RE In DB.Res_Estab Where _ (RE.Estab_Code = Estab_Code) Group By RE.Research Into Group Select Research Because Research is a table, not a value. It renders the error "A group by expression can only contain non-constant scalars that are comparable by the server." So I'm splitting in two queries: Dim...

Choosing a schema for SQL lookup table in the context of LINQ to SQL: sql_variant or multiple fields

I have a question similar to this but in the context of L2S. I want to create a lookup table to store values that could be one of several possible datatypes. As suggested in the referenced question, I could use sql_variant datatype. However, L2S maps sql_variant to Object, which is suboptimal. I'm guessing it's possible to get at the tab...

How do you validate multi-part models?

I'm working on a really big order form with a bunch of multi-part data that's submitted all at once. I'm using that trick where you render 30-40 item rows in the HTML and allow the user to "show" or "hide" more or less using jQuery. The problem is that while the user may have, say, three rows "showing" and they happen to fill all three ...

LINQ-to-SQL The EntitySet is already loaded and the source cannot be changed.

I have an app which uses Linq2SQL to retrieve parent/child data. The parent data is stored in a binding source, Me.SampleDataBindingSource, and the child data in Me.MeasurementsBindingSource. When I create a new SampleData entity, the program works fine. But, when I try to retrieve an existing entity, I get the following error: Syst...

Pass a function to LINQ query.

I'd like to pass a function to LINQ queries to do operations on existing data. For eg. I have this function: string doStuff(Product prod) { return string.Format("{0} - {1}", prod.f1, prod.s2); } When requesting products, i'd like to pass in this function so it returns this string and assign it to a product property NewString. An...

linq to sql datacontext, inserting objects and retrieving the id and appending it to another table??

Wierd question title... What i am trying to accomplish is pretty simple i think. I got 3 tables in the database, BlogPost - BlogPostTagsConnection - Tags The blogpost contains text, title, slug, author, id etc. The BlogPostTagsConnection contains the BlogPost id and the Tags id and finally the Tags contains tagid and tag. So i tried...

get array of table columns in LINQ To SQL

How to get an array of data columns via LINQ To SQL? I'm looking for something like this : DataColumn[] dc = DataContext.Table.Columns; ...

LINQ to SQL with Repository Pattern

Hi all, Currently I'm trying to implement LINQ to SQL in my project. I'm trying to use LINQ to SQL with the famous repository pattern. here is what I was trying to do: Create table, for example customer table. Generate LINQ to SQL (.dbml) for my customer table. It generated partial Customer class complete with all the properties and s...

Linq to jet oledb for microsoft access

Possible Duplicate: Query Microsoft Access MDB Database using LINQ and C# hi is anyone who knows linq to jet-oledb for microsoft access ? ...

Linq-to-SQL: property without a storage column

hey, there, is there any way to ass a NON DB property to a Linq-to-SQL class? (etc calculated fields), I'm getting an error when trying ...

How to erase all records from a database when using LINQ and tableadapter?

Hi, I am trying to load data from Excel file to DataGridView in my Form. First I load all data from excel sheet into dataset then put all that data in database using C# LINQ and then I just set the DataGridView.DataSource to name.BindingSource and that is it. I get all the data in DataGridView but when I try to load the data again (I ha...

How to enforce unique constraint with LINQ to SQL

Hi, I'd like to enforce a unique constraint on two columns with LINQ to SQL. I have got a constraint configured on a SQL table, but is there a way to use it with LINQ to SQL? Unique constraint is applied to two columns, both of which are foreign keys. Thank you Edit: I could catch exception, that's if a very specific exception gets t...