linq

List<T>.Contains not showing overload

I'm sure that I'm missing something simple here, but in Visual Studio 2008 on my current project only List.Contains(T) is present. Being able to use List.Contains(T, IEqualityComparer(T)) would save me a lot of grief. Any quick thoughts on this? Thanks. *edit: using System.Linq is not available to me. Is is possible that my project is ...

Problem with LINQ to Entities and String.StartsWith

I'm trying to build a search page using LINQ to Entities, but the following code is giving me a runtime error about l.t.e. not recognising 'Boolean StartsWith(). The code compiles just fine. How can I work around this better than shipping the StartsWith filtering out to a stored proc? return from dp in dents.DirectoryPersonEntrySe...

ADO.NET Entity Framework SaveChanges() does not work

I want to add new admin into my database. But it doesn't work it. Please look at the button1_Click event handler, I need to add value in this event. public partial class Form1 : Form { protected NetTanitimTestEntities adminNameContext; public Form1() { InitializeComponent(); adminName...

How to call stored procedure without error in ADO.NET Entity Framework?

How do I call a stored procedure without error in ADO.NET Entity Framework? If I use the code below, I get an error: adminNameContext.AddItemCategory(12, "ggf", DateTime.Now); Error: The data reader is incompatible with the specified 'NetTanitimTestModel.Categories'. A member of the type, 'ID', does not have a corresponding column i...

Problems with ANY and OR queries in Linq to NHibernate

I am having some problems with a few queries using Linq to NHibernate. These queries are fairly simple for me to do in SQL but for some reason I am having problems with Linq For example if I want to find all entities which have any of a list of tags attached like this (I have greatly simplified the code for this message): public class ...

How to add to a list using Linq's aggregate function C#

I have a collection of objects of one type that I'd like to convert to a different type. This can be done easily with foreach, but I'd like to figure out how to use Linq's aggregate function to do it. The problem is all the Aggregate examples use types line string or int, which support the '+' operator. I'd like to have the accumulato...

linq to sql , model first development ?

Hi, Is is it possible to use l2s in model first approach? Here's the think i want to achieve: I want to write my app in TDD manner, so I want to write some domain specific objects first and then base on that generate database model. One solution is to l2s as DAL but and map linq generated entities to my custom domain objects(I Rob C. in...

LINQ Select() function throws out loaded values (loadoptions)

Hi All, I have a model where a Product can have multiple PriceDrops. I'm trying to generate a list of products with the most recent price drops. Getting the most recent price drops with the products loaded is easy enough, and I thought it would be the best way to start: dlo.LoadWith<PriceDrop>(pd => pd.Product); db.LoadOptions = dlo;...

Linq2Sql: Can I create entities with foreign key relationships without a primary key in both tables?

I have 2 tables in my database that I'm trying to create Linq2Sql entities for. There's more to them than this, but this is essentially what they come down to: Rooms UserActivity -------- -------- RoomID ActivityID RoomID (foreign key on Rooms.RoomID) The UserActivity table is essentially just a...

Are Update/Delete/Insert on the Linq Roadmap?

Like SQL, Linq is a great way to retrieve data from various sources, but to date I haven't heard anyone talking about the other elements that SQL provides, specifically update/insert/delete. The various DLinq providers all offer their own mechanisms, but it seems like at some point modification of a data source would become part of the l...

C# Linq to SQL: How to express "CONVERT([...] AS INT)"?

In MSSQL you can convert a string into an integer like this: CONVERT(INT, table.column) Is there any C# expression that Linq to SQL would translate to this? In C# you can normally do the same by using int.Parse(), but unfortunately, trying to use int.Parse() in a Linq query results in an error: Method 'Int32 Parse(System.String)'...

An analog of String.Join(string, string[]) for IEnumerable<T>

class String contains very useful method - String.Join(string, string[]). It creates a string from an array, separating each element of array with a symbol given. But general - it doesn't add a separator after the last element! I uses it for ASP.NET coding for separating with "<br />" or Environment.NewLine. So I want to add an empty r...

Counting the result LINQ

I am using the following var validLogin = from P in this.DataContext.Persons where P.UserName.Equals(login) && P.Password.Equals(password) select new { P.FirstName, P.LastName, P.EmailAddress }; In this now i want to know, is t...

C# Extract list of fields from list of class

I've got a list of elements of a certain class. This class contains a field. class Foo {public int i;} List<Foo> list; I'd like to extract the field from all items in the list into a new list. List<int> result = list.ExtractField (e => e.i); // imaginary There are surely multiple ways to do that, but I did not find a nice-looking s...

Stored Procedure returning an int

Hi i have the following stored proc in SQL Server 2005: ALTER PROCEDURE [dbo].[slot_sp_EngineerTimeslots_Group] @PROPREF VARCHAR(50), @PRIORITYCODE VARCHAR(3), @JOBLENGTH INT = 0, @TIMESLOT VARCHAR(3) AS SET NOCOUNT ON DECLARE @TOTALDAYS INT DECLARE @TOTALDAYSTARGET INT DECLARE @COUNTER INT ...

How to Edit data in nested Listview

I am using listview to display a list of items and a nested listview to show list of features to each item. Both parent and child listview need to able Insert,Edit and delete operation. It works fine for parent listview. But when I try to edit an child item, The edit button does not take it into Edit mode. Can you please suggest me what ...

LINQ default methods for insert/delete/update are coming disabled in visual studio 2008

LINQ default methods for insert/delete/update are coming disabled in visual studio 2008. The methods are grayed out (Use Runtime) and can't change to custom Stored procedures. I am using ASP.NET MVC web application and LINQ to SQL. Any help will be apreciated. Many Thanks. ...

Getting value from VAR

For the following code var validate = from P in this.DataContext.Persons where P.UserName.Equals(login) && P.Password.Equals(password) select new { P.FirstName, P.LastName, P....

How Can I get return values returned by stored procedure using InsertOnSubmit in LINQ

Can I get return values returned by stored procedure using InsertOnSubmit in LINQ. The stored procedure return a error number. How can I get this error number InsertOnSubmit (using stored procedure instead of Runtime sql). Many Thanks ...

Sorting an observable collection with linq

I have an observable collection and I sort it using linq. Everything is great, but the problem I have is how do I sort the actual observable collection? Instead I just end up with some IEnumerable thing and I end up clearing the collection and adding the stuff back in. This can't be good for performance. Does anyone know of a better ...