linq-to-sql

LINQtoSQL: Query to return List<String>

I have a LINQ query that returns some object like this... var query = from c in db.Customers where ... select c; Then I do this List<String> list = new List<String>(); foreach (ProgramLanguage c in query) { //GetUL returns a String list.Add(GetUL(c.Property,c.Property2)); } Is...

Storing object into cache using Linq classes and velocity

I careated couple of linq classes & marked the datacontext as unidirectional. Out of four classes; one is main class while other three are having the one to many relationship with first one; When I load the object of main class & put into the memory OR serialize it into an XML file; I never get the child class data while it is maked as D...

How can I do more than one level of cascading deletes in Linq?

If I have a Customers table linked to an Orders table, and I want to delete a customer and its corresponding orders, then I can do: dataContext.Orders.DeleteAllOnSubmit(customer.Orders); dataContext.Customers.DeleteOnSubmit(customer); ...which is great. However, what if I also have an OrderItems table, and I want to delete the order i...

When using skip and take to page data, how can I get the total record count without a separate query?

I don't see how this is possible, but I really, really hate to run my query an extra time just to get the record count so I can build a pager. When I say a "pager" I simply mean the common gizmo with a link for each 10 records for example. ...

Compiled Linq & String.Contains

i'm using linq-to-sql and i'm use complied linq for better performance. I have a users table with a INT field called "LookingFor" that can have the following values.1,2,3,12,123,13,23. I wrote a query to return the users based on the "lookingFor" column i want to return all users that contains the "lookingFor" value (not only those eq...

LinqToSQL: Not possible to update PrimaryKey?

I have a simple table (lets call it Table1) that has a NVARCHAR field as the PK. Table1 has no association with any other tables. When I update Table1's PK column using LinqToSQL it fails. If I update other column it succeeds. I could delete this row and insert new one in Table1, but I don't want to. There is a transaction table which ...

Set Linq To Sql Binary field to null

Trying to set a Binary field to null gives me an ArgumentNull exception. I can set the field to be empty like this new Binary(new byte[] {}); but that's not null just an empty column. Is there a workaround using LinqToSql ? ...

How To Join Tables from Two Different Contexts with LINQ2SQL?

I have 2 data contexts in my application (different databases) and need to be able to query a table in context A with a right join on a table in context B. How do I go about doing this in LINQ2SQL? Why?: We are using a SaaS product for tracking our time, projects, etc. and would like to send new service requests to this product to p...

Linq to sql - delete some related records

Hey! I´m using linq to sql and I have a lot of tables with foreign keys leading to the UserId. Is it possible to have some of these foreign tables cleaned upon deletion. For example I want the users profile (other table) to be deleted automatically with the user but not the users forum posts. Is this possible or do I have to handle ...

WPF, Linq to SQL, C# > How to Populate and Save A Combobox

Pulling my hair out. I've got a table 'Belts' with columns 'BeltID' and 'BeltColor'. I've got a Linq to SQL generated class, and am trying to populate a combobox and it's only partially working. Here's what I've got so far: private void Window_Loaded(object sender, RoutedEventArgs e) { using (DojoDataClassesDataContext conn = new Do...

Linq DBML multiple sql servers

I have an archive system that had to be on two sql databases for simplicity one is Archive2009 and the other Archive2010 they are both on the same sql server and instance and have identical structures however I have a page that needs to view the old one and the new one (I can make two seperate pages) How best would I go about doing...

Is it worth a try LINQ to SQL as a beginner to an ORM?

Thus far used sql server stored procedures for all my web applications... Now thought of moving to an ORM... I would like to ask SO users about LINQ to SQL Is Linq to sql worth a try as a beginner to an ORM? or should i look for some others... Any suggestion... EDIT: I have a sql server 2005 database with all tables.... How to use t...

LINQ2SQL and SQL Server 2000

Good day! I have used LINQ2SQL with SQL Server 2005, but now I need to use it with SQL Server 2000. I have found only article on MSDN that tells about Skip() and Take() oddities on SQL Server 2000 (that's because it lacks ROW_NUMBER(), I suppose) and nothing more. Anyway, does anybody have experience with LINQ2SQL and SQL Server 2000 c...

Passing a LINQ DataRow Reference in a GridView's ItemTemplate

SOLVED. Code has been edited to reflect solution. Given the following GridView: <asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="false" DataKeyNames="UniqueID" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" > <Columns> <asp:BoundField HeaderText="Remarks" DataField="Remarks" /> <asp:TemplateFi...

LINQ to sql return group by results from method

How do I create a method to return the results of a group by in LINQ to sql such as the one below: internal SomeTypeIDontKnow GetDivisionsList(string year) { var divisions = from p in db.cm_SDPs where p.acad_period == year group p by new { ...

linq2sql - where to enlist transaction (repository or bll)?

My app uses a business layer which calls a repository which uses linq to sql. I have an Item class that has an enum type property and an ItemDetail property. I need to implement a delete method that: (1) always delete the Item (2) if the item.type is XYZ and the ItemDetail is not null, delete the ItemDetail as well. My question is wh...

LEFT OUTER JOIN in Linq - How to Force

I have a LEFT OUTER OUTER join in LINQ that is combining with the outer join condition and not providing the desired results. It is basically limiting my LEFT side result with this combination. Here is the LINQ and resulting SQL. What I'd like is for "AND ([t2].[EligEnd] = @p0" in the LINQ query to not bew part of the join condition b...

Using ASP.NET MVC, Linq To SQL, and StructureMap causing DataContext to cache data

I'll start by telling my project setup: ASP.NET MVC 1.0 StructureMap 2.6.1 VB I've created a bootstrapper class shown here: Imports StructureMap Imports DCS.Data Imports DCS.Services Public Class BootStrapper Public Shared Sub ConfigureStructureMap() ObjectFactory.Initialize(AddressOf StructureMapRegistry) End Su...

Save XML File using LINQ to SQL on XML Field

Hi, i have a SQL Data Base. On this DB i have a Table with a XML Field. I wan to save a XML file on the XML Field using LINQ to SQL. It is possible? Thanks. Sorry for my poor english ...

prefix linq2sql entities

is there any option to prefix LINQ2SQL entities like modifying a T4 template or anyconfiguration change? ...