Stefan Sedich's Blog
try { Stefan.Code(); } catch(BadCodeException) { NotLikely(); }
-
Handling Default Values With LINQ to SQL
Hi All,
-
PNG Fix Component
Needing a solution to fix transparent PNG in IE6 I came to start using one of the many javascript based solutions to do this. But when it came time to use ajax and populating new images in my postbacks this obviously broke. So I created a custom ASP.NET Component to help me do this...
-
I Think I Love LINQ
I am beggining to really like to ease of using LINQ, On a project I am working on now I am storing configuration in an XML file like so:
<sites>
<site id="1" sitename="foo">
<domains>
<domain url="www.foo.com" />
</domains>
<settings>
<setting key="foo" value="foo" />
</settings>
</site>
</sites>
My original solution to load this involded looping over the nodes looping over the domains and settings and loading this into my Site object. Time consuming to write and looked messy. And then LINQ to XML steps in. My code to parse this XML file into my collection of Site objects now becomes:
Me.Sites = (From site In document.Descendants("site") _
Select New Site With { _
.ID = site.Attribute("id").Value, _
.SiteName = site.Attribute("sitename").Value, _
.Domains = (From domain In site.Elements("domains").Descendants("domain") _
Select domain) _
.ToDictionary(Function(domain) domain.Attribute("url").Value, Function(domain) domain.Attribute("url").Value), _
.Settings = (From setting In site.Elements("settings").Descendants("setting") _
Select setting) _
.ToDictionary(Function(setting) setting.Attribute("key").Value, Function(setting) setting.Attribute("value").Value) _
}).ToList()
The speed of this is actually pretty fast and I tested with some large XML files and was happy with the performance. And I dont think life can get easier....
Cheers -
Tagging Implementation with LINQ
I decided to implement tagging on my video library. My first solution was to use one table for the tags. Containing the videoid and tagname. When I loaded in 1,000,000 test tags this became slow to generate my tag cloud data. My new solution was to split up the tags into two tables. One containing distinct tags and the other joining videos to them. I will also show some things I came by when extracting my tag data.
Tables
My tables for tagging are as follows:
Tags = {
ID,
TagName
}
VideoTags = {
ID,
TagID,
VideoID
} -
BLL With LINQ
Hello,
-
Unexpected results with Compiled Queries and LINQ to SQL
SOLUTION:
Ok fired up SQL profiler and see my problem, the non compiled query seems to not evaluate the query until you actualy use the object. But the Compiled version is hitting the database straight away. And as I was not using this data the non compiled version seemed fast as it never hit the database to get the data.. So added a .ToList() on my non compiled query and am now getting the results I expected:
Non Compiled: 143ms -Compiled: 78ms
Sorry to all, any input is always appreciated... -
Wierd behaviour with LINQ to SQL designer (bug????)
This is odd. Have a test table with an id and name field no primary key was set as it was a quick test hack. Pulled the table into the LINQ Designer and noticed none of the validation partial methods were there. There was no OnnameChanged. Nowhere. After banging my head I made ID a primary key and boom everything decided to appear.
-
ParameterizedThread in .NET 1.1
Had a problem where I wanted to run a function in a thread but it expected multiple params. So I went around making the ParameterizedThread Class which helped me to execute this method.
-
An ASP.NET Ajax SEO Idea
This is my first post on here so I hope it is helpful.
-
Welcome
Welcome to my blog. I'd like to thank Joe for setting up the blog for me.