linq

Entity Framework Insert In Code

I have a simple Entity Framework. For simplicity's sake I will transform the entity names to Northwind Like. I have a IEnumerable Of Customer and Item Objects I am trying to Create Orders which of course is made up (simplistically) of an Item and A Customer. How can I go about creating and inserting these Orders? -Hcane ...

C# Linq seeing Audit Logout after every read

This is not http://stackoverflow.com/questions/279401/sql-connection-pooling-and-audit-login-logout. I've got a C# .NET 3.5 app that updates about 30K records on SQL 2008 on a local database. The logic is it first checks to see if the record exists SingleOrDefault(p => p.stock=stock && p.number=number) and either adds the record or upd...

LINQ XML column does not update on submitchanges()

Hello, I'm having an issue with LINQ-SQL not updating an XML column. I've run in debug and all values are correct, and when checking the table data I find out that the XML has not been updated. Also any suggested reading on DataClassesDataContext vs DataContext? Code: ///TEST LINQ MIHAI NEW XML protected void testLINQ() { using...

LINQ to SQL Left Outer Join

Hi, Is this query equivalent to a LEFT OUTER join? //assuming that I have a parameter named 'invoiceId' of type int from c in SupportCases let invoice = c.Invoices.FirstOrDefault(i=> i.Id == invoiceId) where (invoiceId == 0 || invoice != null) select new { Id = c.Id , InvoiceId = invoice == null ? 0 : invoice.Id } ...

What would this sql query (w count and group by) look like when translated to linq?

How would the following sql query look when translated to linq? SELECT myId, Count(myId) FROM MyTable GROUP BY myId I've tried the following: var q = from a in db.MyTable group a by a.Id into g let count = g.Count() select new { Count = Id, Key= g.Key }; but it raises an exception on enumeration indicating that there is n...

Concatenate collection of XML tags to string with LINQ

I'm stuck with using a web service I have no control over and am trying to parse the XML returned by that service into a standard object. A portion of the XML structure looks like this <NO> <L>Some text here </L> <L>Some additional text here </L> <L>Still more text here </L> </NO> In the end, I want to end up with one String...

Linq Map! or Collect!

What is the Linq equivalent to the map! or collect! method in Ruby? a = [ "a", "b", "c", "d" ] a.collect! {|x| x + "!" } a #=> [ "a!", "b!", "c!", "d!" ] I could do this by iterating over the collection with a foreach, but I was wondering if there was a more elegant Linq solution. ...

Server-side equivalent of HttpContext?

I have a web app that currently uses the current HttpContext to store a LINQ Data Context. The context is persisted for the current request, on a per user basis, per Rick Strahl's blog: string ocKey = "ocm_" + HttpContext.Current.GetHashCode().ToString("x") Thread.CurrentContext.ContextID.ToString(); if (!HttpContext.Current.Items.C...

Linq query loses order

I have a view in my database that produces ordered results, but when I run a Linq query over that view, the results are no longer ordered (at least, according to the foreach I use to iterate over the results, and according to the debugger). Is this a known difficulty with Linq, or am I missing something? Update: my view, from SQL Serve...

How can I connect an oracle data base with a dbml file?

Hi, I think the best way to use Oracle with LINQ is to map the data base tables into the dbml file by hand. Am I right? When I have done it, then what? How can i connect the data base with the dbml file? ...

Linq Count Returned Results

//Feedback Check var generalFeedbackQuery = from feedbackElements in xml.Elements("feedback") select new { Feedback = feedbackElements.Element("general").Value, PostiveFeedback = feedbackElements.Element("positive").Value, ...

Silverlight 3 - RIA Services and LINQ

Hi This is a basic LINQ question. In my RIA Services Application, I have a Family object with Contacts in a child list. This is a entity framework application. I am wondering why when I select my fam the child list of Contacts are not loaded, well I know that it must because of lazy loading but how to I get my query to load the child...

Add property to LINQ that is combination of multiple tables?

I currently have 3 separate tables : Course, Category, and CourseCategory. CourseCategory is the connection only having the CourseID and CategoryId. I need a way in LINQ-to-SQL to add a Category property to Course objects that abstracts past the multiple tables. We need to change the application to only allow one category, but we don'...

Removing an item from a list - C#

I have rather a complex datastructure. The simple version looks like this: public class Field { List<FieldRow> fieldRow; //I want to write a delete that iterates and deletes given the key //(Use Linq?) public void DeleteByKey(int key) { //Do Remove } } public class FieldRow { public int key; } Any help in impleme...

Linq To Sql - Update not being persisted.

I am really confused about why an update is not taking place. This is very simple: int goodID = 100; DataContext db = new DataContext(); Schedule schedule = db.Schedules.Single(s => s.ID == goodID); // this wont persist - WHY NOT?! schedule.Email = txtEmail.Text; // this does persist schedule.NumberCourse...

LINQ to DataSet, distinct by multiple columns

Just wanted to check if there is way to do distinct by multiple columns. Thanks in advance!!! BTW, I found a great LINQ extension here but need some guidance to use it for multiple columns ...

Linq to Xml and custom xml entities

I want to create a MathML document from an expression tree using Linq to xml, but I cannot figure out how to use the MathML xml entities (such as and &InvisibleTimes): When I try to create directly a XElement using XElement xe = new XElement("mo", "&InvisibleTimes"); it justs escapes the ampersand (which is no good). I also tried to ...

Generate Complex Object from LINQ to XML in VB .NET

I have an XML File that I am processing using LINQ. I want to basically serialize the XML data into custom objects but don't know how. Simplified XML <Data> <Group id="1"> <Child id="1"/> <Child id="2"/> <Child id="3"/> </Group> <Group id="2"> <Child id="1"/> <Child id="2"/> <Child id="3"/>...

Ignore read-only class properties when using DataContext.ExecuteQuery<T>

How do I tell a LINQ data context to ignore either specific properties, or all readonly properties, when binding a result set to an object? I am working with some T-SQL statements that are difficult to express using LINQ, so I'm using the ExecuteQuery method of the data context to pass the straight T-SQL to the database. If my class T ...

LINQ In Line Property Update During Join

I have two obects, A & B for this discussion. I can join these objects (tables) via a common relationship or foreign key. I am using linq to do this join and I only want to return ObjectA in my result set; however, I would like to update a property of ObejctA with data from ObjectB during the join so that the ObjectAs I get out of my ...