Saturday, January 30, 2010
I thought I would share a nice small tweak I made to a LINQ to SQL model. Assume I have the following table structure for ‘Categories’: I faced with the need to select categories while ordering it by the combination of Description1 and Description2 (Note: nullable fields). I entered some dummy data to the table to illustrate the point: The goal is to retrieve the order as follows: 1, 3, 5, 2, 4 After explaining that, lets forward to the LINQ statements then. Take 1...
Thursday, January 15, 2009
Someone asked me what the difference between descendants and elements is, I thought I'd post the details here for common interest.Descendants will yield you elements of your choice from the entire source element sub-tree, whereas Elements will yield the child elements only.E.g. string xml = @" <Root> <Item> <id>1</id> </Item> <Item> <id>2</id> </Item> <Item> <id>3</id> <Items> <Item> <id>5</id> </Item> <Item> <id>6</id> </Item> </Items> </Item> <Item> <id>4</id> </Item> </Root>"; XDocument doc1 = XDocument.Parse(xml); var q1 = from e in doc1.Root.Descendants("Item") select e; var q2 = from e in doc1.Root.Elements("Item") select e; int c1 = q1.Count(); //6 int c2 = q2.Count();...
Via this post.
The post discusses the issue of using LINQ-to-SQL with dynamic mappings.
The problemYou have SQL Servers for each of your environments (development, test, pre-prod, production) and in each one, the table names are different. In fact, it’s not the table names that are different but the schema names but since the schema name is part of the table name, it must be specified.Ex : dev.ZeTable et prod.ZeTable
Easy to solve, right? Just put the schema value in the config file and do a simple concatenation at runtime. Well, it’s not as easy as it seams because the table name...
Via this post by Roy Osherove.
A nice approach for working against regular expressions.I must admit, it looks as if it would take some time to master and love.
Nice to know it's out there :)
public void FindEmailUsingPattern()
var query = from match in
foreach (var match in query)
A great post by Terry Aney.
The post explains the gotchas when using LINQ to SQL to perform batch updates and deletes and offers an elegant and a very impressive solution!
Worth checking it out.
A new version of LINQ to XSD had been released last week.
The new version works with the final release of VS 2008.
"The LINQ to XSD preview illustrates our initial thinking on a strongly-typed programming experience over LINQ to XML. Instead of working with untyped XML trees, LINQ to XSD allows you to program in terms of strongly-typed classes, generated based on an XSD schema."
Follow this link to get the details and download information.