linq

linq, mvc and partial class

I have dbml with single table users i want add partial class for User and add another property like so: public partial class User { public string FullName { get { return FirstName + " " + LastName; } } } and then use in my View something like: <%...

Handling very large strings between SQL Server and .NET code +LINQ

I have an app that needs to handle very large strings between a SQL Server database and .NET code. I have a LINQ query that generates the strings when saving them to the database, but when trying to create the strings from the database, the app crashes with an OutOfMemoryException because of the size of the strings. Do I have to do some...

"Cannot call methods on DateTime", and other limitations

Does anyone know of a definitive list of LINQ to SQL query limitations that are not trapped at compile time, along with (where possible) workarounds for the limitations? The list we have so far is: Calling methods such as .Date on DateTime no workaround found string.IsNullOrEmpty simple, just use == "" instead .Last() we used .Or...

Calling generic method with a type argument known only at execution time

Edit: Of course my real code doesn't look exactly like this. I tried to write semi-pseudo code to make it more clear of whay I wanted to do. Looks like it just messed things up instead. So, what I actually would like to do is this: Method<Interface1>(); Method<Interface2>(); Method<Interface3>(); ... Well ... I thought that maybe I...

How to return an array back from a function from a LINQ annonymous list

Hi all, Essentially i want to have a generic function which accepts a LINQ annonymous list and returns an array back. I was hoping to use generics but i just can seem to get it to work. hopefully the example below helps say i have a person object with id, fname, lname and dob. i have a generic class with contains a list of objects. i...

Selectively remove from where clause in LINQ expression tree

Starting with the following LINQ query: from a in things where a.Id == b.Id && a.Name == b.Name && a.Value1 == b.Value1 && a.Value2 == b.Value2 && a.Value3 == b.Value3 select a; How can I remove (at runtime) one or more of the conditions in the where clause in order to obtain queries similar to the following ones: from a ...

How do I create this expression tree in C#?

I am trying to create an expression tree that represents the following: myObject.childObjectCollection.Any(i => i.Name == "name"); Shortened for clarity, I have the following: //'myObject.childObjectCollection' is represented here by 'propertyExp' //'i => i.Name == "name"' is represented here by 'predicateExp' //but I am struggling w...

How do you do a SQL style 'IN' statement in LINQ to Entities (Entity Framework) if Contains isn't supported?

I'm using LINQ to Entities (not LINQ to SQL) and I'm having trouble creating an 'IN' style query. Here is my query at the moment: var items = db.InventoryItem .Include("Kind") .Include("PropertyValues") .Include("PropertyValues.KindProperty") .Where(itm => valueIds.Contain...

REST web services and .NET

What's the best way to consume REST web services from .NET? ...

How much overhead does 'Update Check' have for LINQ UPDATES

I have a simple row that I edit using LINQ. It has about 30 columns, including a primary key numeric sequence. When an UPDATE is performed through LINQ, the UPDATE statement includes all the columns of the table (for concurrency checking). I'm wondering how inefficient this is - if not negligibiel. Since there is an index on the prima...

Setting LinqDataSource bound DropDownList using URL querystring

Hi folks, This is a puzzle for me, I am able to get three DropDownLists to behave like a cascade (it fetches the correct data) but where I run into problem is where I try to set the value for the dropdownlist based on the value of the querystring. Only the first dropdownlist seems to take it's value from the querystring. The other t...

IEnumerable.Except wont work, so what do I do?

I have a linq to sql database. Very simplified we have 3 tables, Projects and Users. There is a joining table called User_Projects which joins them together. I already have a working method of getting IEnumberable<Project> for a given user. from up in User_Projects select up.Project; Now I want to get the projects the user isn't i...

Linq to XML - update/alter the nodes of an XML Document

Hello! If got 2 Questions: 1. I've sarted working around with Linq to XML and i'm wondering if it is possible to change a XML document via Linq. I mean, is there someting like XDocument xmlDoc = XDocument.Load("sample.xml"); update item in xmlDoc.Descendants("item") where (int)item .Attribute("id") == id ... 2. I already know how ...

Is it possible to Serialize a LINQ object?

I'd like to serialize some LINQ generated objects and store them in a table as a binary field (Never you mind why). I'd like to be able to write some code that looks something like this: SerialTestDataContext db = new SerialTestDataContext(); relation_table row = db.relation_tables.First(); MemoryStream memStream = new MemoryStream();...

Does this linq query run on every iteration of the for-each loop?

In another question on SO I answered with code like the one below and got a comment that the LINQ-query probably was evaluated in every iteration of the for/each. Is that true? I know that LINQ-querys does not executes before its items is evaluated so it seems possible that this way to iterate the result can make it run on every iterati...

LINQ: Check whether an Array is a subset of another

Any idea on how to check whether that list is a subset of another? Specifically, I have List<double> t1=new List<double>{1,3,5} List<double> t2=new List<double>{1,5} How to check that t2 is a subset of t1, using LINQ? ...

Linq insert with no primary key

I need to insert records into a table that has no primary key using LINQ to SQL. The table is poorly designed; I have NO control over the table structure. The table is comprised of a few varchar fields, a text field, and a timestamp. It is used as an audit trail for other entities. What is the best way to accomplish the inserts? Cou...

How does Linq work (behind the scenes)?

I was thinking about making something like Linq for Lua, and I have a general idea how Linq works, but was wondering if there was a good article or if someone could explain how C# makes Linq possible Note: I mean behind the scenes, like how it generates code bindings and all that, not end user syntax. ...

Do you ToList()?

Do you have a default type that you prefer to use in your dealings with the results of LINQ queries? By default LINQ will return an IEnumerable<> or maybe an IOrderedEnumerable<>. We have found that a List<> is generally more useful to us, so have adopted a habit of ToList()ing our queries most of the time, and certainly using List<> in...

Linqtosql remove from list

myRule.ToList().RemoveRange(0, count); Even though it does not give me error, it does not work. What's the other way? ...