linq

Child objects in MongoDB

I have been following along with Rob Conery's Linq for MongoDB and have come across a question. In the example he shows how you can easily nest a child object. For my current experiment I have the following structure. class Content { ... Profile Profile { get; set; } } class Profile { ... } This works great when looking a...

Comparing multiple entity properties against list of entities

Consider this snippet of code: var iList = new List<Entities.Ingredient> { new Entities.Ingredient { Name = "tomato", Amount = 2.0 }, new Entities.Ingredient { Name = "cheese", Amount = 100.0 } }; var matches = new DataContext().Ingredients.Where(i => Comparer(i, iList)); private Boolean Comparer(Entities.Ingredient i, List<...

querying nested array elements in C#

I have following object structure, deseralized from XML (WS): <ns2:Category> <ns2:CategoryId>800003</ns2:CategoryId> <ns2:CategoryName>Name1</ns2:CategoryName> <ns2:Categories> <ns2:Category> <ns2:CategoryId>800008</ns2:CategoryId> <ns2:CategoryName>Name2</ns2:CategoryName> <ns2:Categories> <ns2:Categ...

How to use Linq group a order list by Date

I have a order list and want to group them by the created date. Each order's created datetime will be like "2010-03-13 11:17:16.000" How can I make them only group by date like "2010-03-13"? var items = orderList.GroupBy(t => t.DateCreated) .Select(g => new Order() { DateCreated = g.Key }) .OrderByDescending(x => x.OrderID...

Linq sql Attach, Update Check set to Never, but still Concurrency conflicts

In the dbml designer I've set Update Check to Never on all properties. But i still get an exception when doing Attach: "An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported." This approach seems to have worked for others on here, but there must be ...

What's the meaning of the angle brackets on LINQ methods in Intellisense? (Contains<>, Count<>, Distinct<>, etc.)

They usually involve generics. But some methods with generics don't have them, and not all extension methods have them. They've just "been there" since day one, we've all seen them; but I realized I still don't know what they mean, and I can't find the answer anywhere. Now it's really bugging me. Google just turns up results that a...

Will linq to sql work in an asp.net 2.0 web application?

Will linq to sql work in an asp.net 2.0 web application? Just realized the server doesnt' support asp.net 3.5 (no control over it!) ...

Delete with subsonic

I've had problems with the update method in subsonic, so instead of using: a.Update() I used var qry = dbAnimals.Update<Notification>(). Set(n => n.NotName == notification.NotName). Set(n => n.NotRecStatus == notification.NotRecStatus). Set(n => n.NotModified == notification.NotModified...

Linq duplicate removal with a twist

I got a list that contains al the status items of each order. The problem that i have is that i need to remove all the items of which the status -> logdate combination is not the highest. e.g var inputs = new List<StatusItem>(); //note that the 3th id is simply a modifier that adds that amount of secs //to the c...

C# Linq Entity Conversion Error on Nonexistent Value?

While trying to query some data using the Linq Entity Framework I'm receiving the following exception: {"Conversion failed when converting the varchar value '3208,7' to data type int."} The thing that is confusing is that this value does not even exist in the view I am querying from. It does exist in the table the view is based on, ...

Use LINQ and lambdas to put string in proper case

I have this function called ProperCase that takes a string, then converts the first letter in each word to uppercase. So ProperCase("john smith") will return "John Smith". Here is the code: public string ProperCase(string input) { var retVal = string.Empty; var words = input.Split(' '); foreach (var wo...

IEnumerable<IEnumerable<T>> to IEnumerable<T> using LINQ

How to split an IEnumerable of IEnumerables to one flat IEnumerable using LINQ (or someway else)? ...

Get all but first from an array

Is there a one-line easy linq expression to just get everything from a simple array except the first element? for (int i = 1; i <= contents.Length - 1; i++) Message += contents[i]; I just wanted to see if it was easier to condense. ...

Finding if a target number is the sum of two numbers in an array via LINQ and get the and Indices

Hello I am new to Linq , I found this thread which explain 90% of what I need http://stackoverflow.com/questions/2331882?tab=newest#tab-top , thanks "pdr" but what I need is to get the Indices too , here is my modification I get the index of the first number but I don't know how to get the index of the second number int[] numb...

Extract data from an Array

Hello, I have an array DetailsArray in VB.NET which contains the result of a LINQ query. I have shown below the values of the array. i need to get the "ProjectID" from the array and assign it to 'ProjID' variable DetailsArray (0){Name = "TestProject1", ProjectID = 10} Dim ProjID as Integer = DetailsArray(??) How would I do th...

How to use Linq to select and group complex child object from a parents list.

How to use Linq to select and group complex child object from a parents list. I have an OrderList each of order object has a OrderProductVariantList(OrderLineList), and each of OrderProductVariant object has ProductVariant, and then the ProductVariant object will have a Product object which contains product information. My goal is to ...

Constructor or Explicit cast

In working with Linq to Sql I create a seperate class to ferry data to a web page. To simplify creating these ferry objects I either use a specialized constructor or an explicit conversion operator. I have two questions. First which approach is better from a readibility perspective? Second while the clr code that is generated app...

Using LINQ to Extract Specific Values from Multi-Dimensional Array

I am working with multi-dimentioned arrays of bool, int, and various struct. The code loops through these arrays and performs some operation on specific values. For instance, for (int x = 0; x < this.Size.Width; x++) { for (int y = 0; y < this.Size.Height; y++) { if (this.Map[x, y]) { ...

Entity Framework with ASP.NET MVC. Updating entity problem

Hi people. I'm trying to update an entity and its related entities as well. For instance, I have a class Car with a property Category and I want to change its Category. So, I have the following methods in the Controller: public ActionResult Edit(int id) { var categories = context.Categories.ToList(); ViewData["catego...

Problems finding classes in namespace

I am trying to find all of the types in the Models namespace within an ASP.NET MVC assembly from within a testing assembly. I was trying to use LINQ to find the relevant set for me but it is returning an empty set on me. I am sure it is some simple mistake, I am still relatively new to LINQ admittedly. var abstractViewModelType = typeof...