linq-to-sql

Nullable enums(??) and LinqToSQL

I have the following statement: select new Action { ParentContentType = action.ParentContentType != null ? (ContentType)Enum.ToObject(typeof(ContentType), action.ParentContentType) : null }; ParentContentType is a nullable enum of type ContentType action.ParentContentType maps to a database table which is a nullable int. If ac...

Why is my DataContext null in only one action?

I have a property on my BaseController called DataContext that holds my LINQ to SQL data context (or fake context for testing). When using a parameterless constructor (in other words, when a request to ASP.NET MVC is made), a new instance of my LINQ to SQL data context is assigned to the property: public class BaseController : Controlle...

ASP.NET MVC + LINQ to SQL or Entities?

When linq to entities was released, everybody say that linq to sql is dead. But most books and sample projects by microsoft employees, use mvc+linq to sql. There is some reason for that? The linq to sql seems better for POCO, would it? ...

Validate unique keys with asp.net mvc and linq to sql?

I have a sql server table with 2 fields, ID (primary key) and Name (unique key). I'm using linq to sql to produce model objects for asp.net MVC from this table. To perform the model validation I've implemented IDateErrorInfo in a partial class public partial class Company : IDataErrorInfo { private Dictionary<string, string> _error...

LINQ Where in collection clause

Hey guys, I've been looking on google but not finding anything that does the trick for me. as you know SQL has a "where x in (1,2,3)" clause which allows you to check against multiple values. I'm using linq but I can't seem to find a piece of syntax that does the same as the above statement. I have a collection of category id's (List...

Using LINQ2SQL to insert a large number of records...

We have a small c# tool that we threw together to parse a data file, build up some objects and insert them into the DB. The logic is essentially. string [] lines = File.ReadAllLines("C:\\Temp\\Data.dat") foreach(string line in lines) { MyDataObject obj = ParseObject(line); myDataContext.MyDataObjects.InsertOnSubmit(obj); } my...

Unit of Work Design Pattern

Does anyone have any good links about a practical example of Unit of Work pattern with LINQ to SQL ...

ASP.net gridview sorting with linq result

hey guys I'm in a bit of pickle here. up till now I have a linq query that fills a datagrid perfectly with filterconditions. however, when I try to implement sorting I fail. I have the following code behind. it catches the start of the sort. protected void gvServers_Sorting(object sender, GridViewSortEventArgs e) { if (e.SortDire...

What is the equivalent C# 3.0 Linq to SQL for this?

Old VB6 Code that needs to be converted: 'DB Connection Set Conn = New ADODB.Connection Conn.ConnectionString = sConn Conn.Open sConn Conn.BeginTrans 'Recordset Set rsPrice = New ADODB.Recordset rsPrice.CursorLocation = adUseClient rsPrice.CursorType = adOpenKeyset rsPrice.LockType = adLockBatchOptimistic rsPrice.ActiveConnection = Con...

LINQ to SQL and Null strings, how do I use Contains?

Hi all, Here is the query from a in this._addresses where a.Street.Contains(street) || a.StreetAdditional.Contains(streetAdditional) select a).ToList<Address>() if both properties in the where clause have values this works fine, but if for example, a.StreetAdditional is null (Most of the times), I will get a null reference exception....

Getting a linq table to be dynamically sent to a method

I have a procedure: var Edit = (from R in Linq.Products where R.ID == RecordID select R).Single(); That I would like to make "Linq.Products" Dynamic. Something like: protected void Page_Load(object sender, EventArgs e) { something(Linq.Products); } public void something(Object MyObjec...

Linq to SQL : Optimizing queries with Sql Server Compact Edition

Hi I've been using Linq to SQL against Sql Server CE. Database is read only, so I can have several assumptions. In order to refrain from accessing the file system, my initial approach was to cache needed entities to application memory and using linq to objects against them. While it works well for limited queries, directly using Linq...

Return single column with Linq

public string GetNameBySSN(string SSN) { var results = from c in Clients where c.ClientSSN.Equals(IRRCNumber) select c.FirstName; //return results.ToString(); } I want to return a single column value with Linq and not sure if there is way to do a quick easy return. I commented section of c...

LINQ TO SQL :: Data Update Problem

Hi i am developing a project (using 3-tier approach) in which i am using LINQ TO SQL... i want to update user... but i am facing some problem. it does not give me any error but also do not update the user detail here is the program sequence; in UpdateProfile.aspx String currentUser = Session["BMUser"].ToString(); Strin...

LINQ to SQL associations!?

Hi I have a Posts class and that post can have one file and that file can have many tags I want to iterate through the files in a post and show all the files tags foreach(File f in Post.Files) { f.Tags } What do I need in this foreach to get the top tag? there will only ever be one. i tried f.Tags.Select(n => n) with no luc...

Linq-to-SQL Executing NonQuery

Is it possible to use Linq-to-Sql to execute a stored procedure that does not return an output? ...

Dynamic LinqToSQL pivot table query

Hi All http://img7.imageshack.us/img7/3050/downtime.png I have two calendar pickers ( To and From ) I need to build the Year1 -> 4 dynamicly. I am also getting dupplicate records for 1 items that have values for 2006 and 2009. They can select 100 years if they wanted too.Check attached image. public ActionResult DownTimeSummaryTabu...

Can Linq to SQL coexist with ADO in SQL Server Express?

I have a single-user Win Forms application that uses an SQL Server Express database via ADO.NET. I want to add more to my app, but by using Linq to Sql (while I learn Linq to Sql). I am unable to see the database in two places simultaneously. Either I can see it in the original code using ADO, or I can see it with the new code using L...

LINQ to SQL and DataPager

I'm using LINQ to SQL to search a fairly large database and am unsure of the best approach to perform paging with a DataPager. I am aware of the Skip() and Take() methods and have those working properly. However, I'm unable to use the count of the results for the datapager, as they will always be the page size as determined in the Take...

LINQ To SQL "Group By"

I wonder if someone can help me. I want to replicate the following SQL query using LINQ in VB.Net.I'm a little unclear on how to do subqueries / aggregates. Thanks SELECT * FROM Server S INNER JOIN ServerHDD H ON S.Server_ID = H.Server_ID INNER JOIN (SELECT MAX(ServerHDD_ID) AS ServerHDD_ID ...