A simple little linq values transformer
Somehow I’ve never actually used this keyword before, but as I gradually shift over to functional programming I came across the ForEach linq statement – for example listOfObjects.ForEach(x => x.BodyText = x.BodyText.Replace(“,”,”, “)); And bam – all of the body text is replaced without having to loop through the enumerable. Rather nice. A simple little […]
Linq projection with the extension method syntax
I’ve looked this up an embarrassing number of times – here is how you do linq projection with the extension method syntax List<TypeClassification> typeClassifications = ctx.Classes.Select(e => new TypeClassification() {Name = e.Name, TypeClassificationID = e.ClassificationID}).ToList(); Hopefully I shall remember. I’m not sure why I can’t remember the exact syntax.
How to Fix Missing records in Linq to Entities
The Problem You are attempting to use Linq to Entities in the standard way, your linq model does not seem to have any records attached. You have missing records in Linq to Entities. You look in the database, and the proper record is there. You do a context.MyEntry.Count().ToString() and it tells you there is one […]
How to fix problems with Linq to Xml Namespaces
The Problem You are trying to read data out of a standard xml file. I found a great Linq to Xml tutorial here. You get code that looks something like this XDocument data = XDocument.Load(HttpContext.Current.Server.MapPath("~/Invoices.xml")); List<Invoice> lst = new List<Invoice>(); lst= (from c in data.Descendants("invoice") select new Invoice { ClientName = c.Element("client").Value, InvoiceDate = Convert.ToDateTime(c.Element("date").Value), }).ToList(); and you get nothing but object type no found errors. Why? You have problems with linq […]