linq-to-sql

Linq To SQL DAL and lookup data source

I am learning linq to sql and I am trying to setup a lookup combo box in my web page. I was using a linq data source but I then moved my linqtosql code to it's own class library for my DAL dll (took out of app_code folder). So, I am converting the page code to be able to still have lookups driven now by a biz object. Here's what I hav...

What is the quickest way to stream an image from a FILESTREAM in SQL to a browser?

I have images stored in my database in a FILESTREAM and I am trying to find out what the best solution is to get that image back out into a web browser. If I was managing the files on the file system myself, the quickest way would just be: Response.TransmitFile(pathToFile); This does not load the file into memory before transmitting ...

Difference Between Select and SelectMany

Hi, I've been searching the difference between those two but I couldn't find actually what I want. I need learn the difference when using LINQ To SQL but they all gave me standard array examples. Can some one give a LINQ TO SQL Example to show the difference between Select and Select Many. Thanks in advance. ...

Linq to SQL : How do I get the property values from a query's results?

I m just starting with microsoft (MVC,C#, LINQ), so far so good, but i have a question about LINQ uses, How do i get the value form a LINQ like this one? var x = from a in db.tablex where a.eventID == eventID select new { owner = a.owner, ...

LinqToSQL - Read object with only certain properties

Given such table: Foo P1 P2 P3 How can I read Foo with P1 only? My implementation: public Foo GetFooWithP1(int id) { using (DbDataContext db = new DbDataContext()) { var query = from f in db.Foos where f.Id == id select new { P1 = m.P1 ...

LinqToSQL - Read objects Hierarchy with only certain properties

Given: Foo BarId P1 P2 P3 Bar P4 P5 P6 How can I read Foo and Bar with only certain properties? E.g.: Foo { P1 = 111 Bar = { P4 = 444 } } Naive solution: public Foo Read(int id) { using (DbDataContext db = new DbDataContext()) { var query = from f in db.Foos join b in db...

Stack overflow in LINQ to SQL and the Contains keyword

I have an Extension method which is supposed to filter a Queryable object (IQueryable) based upon a collection of Ids.... Note that IQueryable is sourced from my database via a LinqToSql request public static IQueryable<NewsItemSummary> WithID(this IQueryable<NewsItemSummary> qry, IQueryable<Guid> Ids) { return from newsIt...

LINQ not submitting changes

I'm using C# and LINQ to SQL I'm issuing the following command: User cu = CurrentUser; Post newPost = new Post { CreateDate = now, ModifyDate = now, User = cu, ModifyUser = cu, Text = text, Title = title, Thread = t, ResponseToPostID = null }; this.AppManager.DB.Posts.InsertOnSubmit(newPost); this.AppM...

Linq to Sql update creates duplicate record

I'm using linq to sql in my data layer where I have added a "settings" table to the regular asp_user table. In this settings table I keep several records of which one is the prefered Unit (a foreign key to the Units table). Now when this prefered unit needs to change (say from liter to kilogram), I do a call to my UnitService to get the...

My O/R Designer keeps deleting the designer.cs file!

I have a weird problem that sometimes when I make a change to a Linq object using the O/R designer (usually by adding a field that I've added in the DB), when I save the project, the designer.cs file gets deleted! Fortunately I have my source control to fall back on; I undelete the file and back out the changes to the csproj file. But ...

Simple Edit/Update actions using LINQ. Isn't my code a bit wrong?

Consider a simple Edit/Update code: public ActionResult Edit(int id) { return View(db.Foos.Single(x => x.Id == id)); } public ActionResult Update(Foo changed) { Foo foo = db.Foos.Single(x => x.Id == changed.Id); foo.P1 = changed.P1; db.SubmitChanges(); } What I am actually trying to do here is to send: UPDATE [dbo].[...

Updating a single field with Linq to SQL - Can I just disable all concurrency logic?

Yes, this subject is covered on hundreds of posts all over the net, and yet I still haven't found the one that doesn't involve loading an entire entity (sometimes serialized) just to change a single field. Some had suggested that changing "Update Check" on all properties of the entities would resolve this, but so far I'm still getting Ch...

LINQ to SQL - best way to switch between test & dev db

What is the simplest way to programmatically toggle back and forth between test and dev databases using the LINQ to SQL ORM? ...

Linq2SQL and Duplicate records

Hi What would be the best way to check if a record exists in a table. What happens is the user types the same name and I need to see if it is in the database. The thing is that I would like to do it on the Repository base class that uses generics. So I can not go Entity.Name. public void Save(T item) { Table<T> tab...

LINQ to SQL Lookup table? Join perhaps? I'm lost... ;/

Not sure if this is called a lookup table... Here's a screenshot of the schema: http://apoads.com/db-schema.png What I want to do is join the Ad and MilBase table where the MilBase.BaseID is a given value. In the result, I'd like to be able to access the data like so: ad.MilBase.BaseName, etc... I just can't seem to wrap my mind around...

linq2SQL + sum

Hi all I have a bunch of incidences in a table that are linked to a supplier I need to some the serverity score for those incidences by supplier So basicly have supplier1: 500 supplier2: 600 How do I do this? DataAccess.IncidentRepository().GetItems().Where(i => i.IncidentDate.Year == 2006) ...

How to use multiple, nested, transactionscopes?

I am doing a few operation in linq2sql that needs to be run in a transaction. However, some of the methods I use inside of the transaction also uses linq2sql and runs inside a transaction of their own (the inner transaction is run within a stored procedure). This gives me the exception [TransactionInDoubtException: The transaction is in...

Equivalent LINQ to SQL code

Hi there, Am new to this here is my T-SQL SELECT category.id, category.name,COUNT(job.id) AS countofjobs FROM category LEFT OUTER JOIN job ON category.id = job.categoryid AND job.active=1 WHERE category.featured=1 GROUP BY category.id, category.name ORDER BY category.name what will be the equivalent LINQ to SQL code? any help wil...

Getting a multi-dimensional result out of a stored procedure with LINQ to SQL

I am using LINQ to SQL to call a stored procedure with a single result set (I have found a lot of information about handling multiple result sets, but that is not what I am doing). The result set is actually all columns from 3 tables joined together, and I have LINQ to SQL entities for those 3 tables. The schema is something like this: ...

ASP.NET MVC: How too keep orignal object state over the wire

Consider the following code: public ActionResult Edit(int id) { return View(db.Foos.Single(x => x.Id == id)); } When user submits the changes, I would like to receive both original and current object values, such that the Update code can be: Foo foo = db.Foos.Attach(current, original); db.SubmitChanges(); I see two options: 1)...