-
|
If you have a data table which looks like this one below and holds child,parent rows at the same table; ID ParentID Name guid1 null parent 1 guid2 guid1 child for parent 1 so on so on so on and you wont to retrieve all records from the table in a table looks like below; Parent Childs parent 1 child 1 for parent 1 child 2 for parent 1 child 3 for parent 1 …. Parent 2 child 1 for parent 2 child 2 for parent 2 …. This means that i have to make a recursive query in Sql to retrieve it this way. but with LINQ its more easy to be done, see the query below; 1: var q= from p in TypedDataTable 2: where p.ParentID == null // well get all parents 3: select new 4: { 5: ParentID = p.ParentID, 6: child = from c in TypedDataTable 7: where c.ParentID == p.ID...
|
-
|
Linq is used generally to get and manipulate data by using Linq to Sql, Linq to Entities or Linq to Xml. However, it can work on many collections in .NET Framework. Now in this post, I'll show how to work on Page Control Collection with Linq. Think about the scenario you want to get every textboxes that has a text in it. To see which ones we select add them a text you want. Create a new .aspx page and add several textboxes to it. They can be directly in page or another control (i.e. a panel control). Then add the code below to [Further] Read More...
|
-
|
Yesterday one of our project team member faced a challenge of using an anonymous data that is returned from joining 2 typed data tables with LINQ. The problem is not how to use the data, the problem was how to be able to cast and use the data in Repeater ItemDataBond method without having “ <>f__AnonymousType0 ….” cast error. below is the join query (tables used are typed) :- 1: PagedDataSource objPDS = new PagedDataSource(); 2: objPDS.AllowPaging = true ; 3: objPDS.PageSize = 10; 4: 5: objPDS.DataSource = (from p in Table1 6: join d in Table2 on p.ID equals d.ID 7: select new 8: { 9: p, 10: F1= d.f1, 11: F2= d.f2, 12: F3= d.f3, 13: F4= d.f4, 14: }).ToList(); .csharpcode, .csharpcode pre { font-size: small; color: black; font-family...
|
-
|
Caching of frequently used data greatly increases the scalability of your application since you can avoid repeated queries on database, file system or to webservices. When objects are cached, it can be retrieved from the cache which is lot faster and more scalable than loading from database, file or web service. However, implementing caching is tricky and monotonous when you have to do it for many classes. Your data access layer gets a whole lot of code that deals with caching objects and collection, updating cache when objects change or get deleted, expire collections when a contained object changes or gets deleted and so on. The more code you write, the more maintenance overhead you add. Here I will show you how you can make the caching a...
|
-
|
While I was planning to write about the same topic and have the draft ready in my Windows Live Writer waiting to complete, I found an interesting question in StackOVerflow and couldn’t just resist to answer: ORM/Persistence layer Advice The question starts with: I'm starting a new project and I'm looking around for either a very good ORM or for a non-SQL-based persistence layer. Then follows up with a REALLY GOOD summary of what he believes about each known ORM he knew out of his own findings and search. I advice you to go read it. However, all this investigation didn’t get him to a single choice answer. And I can’t blame him. This is one fo the questions that will remain for so long without a single answer, or maybe having the popular...
|
-
|
I decided to post this because I have tried to update my dbml file (LINQ2SQL) several times and I have forgotten the steps. If I write this I should not forget it again. :) For some reason LINQ2SQL has a bug in VS2008 (hope it will be fixed in VS2010) when you modify the dbml file and you have a partial class of the DataContext LINQ class with using statements the Custom tool that generates the code for LINQ class has a problem and it doesn't generate the designer.cs file that contains the generated classes that you will be using in your pages or code. Therefore these are the steps that I have followed with success 1.- Modify the dbml with your changes. 2.- Comment the using statements in the partial class of the LINQ class 3.- Delete the...
|
-
|
.Net Framework 4.0 adds also some new and cool features to file system objects. File class has now ReadLines() methods that returns IEnumerable<string>. WriteAllLines() methods has two overload methods that accept IEnumerable<string> instead of strings array that was also supported in previous versions of .Net Framework. This posting introduces ReadLines() and WriteAllLines() methods and gives you some ideas how to use these methods in your applications. Querying file contents My first example shows how to use ReadLines() to query file contents using LINQ. I have text file called lorem-ipsum.txt with some paragraphs with famous lorem ipsum text. You can generate your own text on www.lipsum.com . I use LINQ query to get all lines...
|
-
|
LINQ brought developers a very user friendly and domain independent style of writing queries. The fact that the way queries are written is domain independent doesn’t mean that any query will compile the same way or even run the same way. You’ll always need to know how the provider will behave. LINQ To Objects , for example, will compile queries as a Func<> delegate and the query methods will return Interface" href="http://msdn.microsoft.com/library/9eekhta0.aspx" target=_blank>IEnumerable(T) implementations. On the other hand, LINQ To SQL will compile queries as an Expression<Func<>> (which is, in fact, an expression tree) delegate and the query methods will return Interface" href="http://msdn.microsoft...
|
-
|
Daily tech links for .net and related technologies - October 9-11, 2009 Web Development Using MvcContrib ScriptInclude, Stylesheet, And T4MVC ASP.NET MVC Cheat Sheets NerdDinner with Fluent NHibernate Part 3 - The infrastructure ASP.NET Profiles in Web Application Projects ASP.NET 4.0 Roadmap 15 Helpful Website Usability Facts & Guidelines How to trigger an ASP.NET validator from JavaScript? ASP.NET MVC learning resource: Request-Handling Pipeline Poster Adventures with the SEO Toolkit Web Design...( read more ) Read More...
|
-
|
Daily tech links for .net and related technologies - October 5-7, 2009 Web Development How To Speed Up Your Website By 80% Or More Enterprise Library Validation example for ASP.NET MVC 2 thinking out loud: asp.net mvc & nhaml ASPhere web.config editor Efficient Server Side Paging With ASP.NET And jQuery 3 Image Techniques To Speed Up Your Website 5+ Steps to Speed up your Website punypng: PNG Compression and Image Optimization Asp.net MVC Areas in depth - on code Web Design How to Code a Clean...( read more ) Read More...
|