menu_left_header Menu
Skip Navigation Links
Home Page
Resume

menu_left_header Twitter
dusda: 2:07am, no update so far here in Portland. I am such a geek... #nxe

menu_left_header Xbox Live
Dusda's GamerCard

LINQ to SQL Serialization Series Part 1: Unidirectional Serialization
Linq to Sql, by default, does not enable serialization. This is no problem when dealing with business objects directly, but what if you throw in Windows Communication Foundation? Or, maybe you have some business requirement mandating the use of Xml files. Luckily, LINQ makes dealing with both of these potential problems quick and painless. This first article shows you how to enable unidirectional serialization, explains how it works, and discusses drawbacks for this approach.

Enabling Xml Serialization in Linq to Sql
First you have to enable Xml Serialization on your LINQ objects.
In Visual Studio, open your DBML file in the ORM Designer. Open the properties pane on the right to see your DBML Data Context Properties. If you don’t see the same properties list shown in the image above, click anywhere in the ORM Designer’s whitespace to ensure you haven’t selected a table or something.


Then, select the drop down list for Serialization Mode and select Unidirectional.


Your LINQ objects now support unidirectional serialization.

How Unidirectional Serialization Works
How it works is actually much more long winded than how to get it done, but it is important to know what wizardry the ORM designer is doing for you, and helps me explain a few things later. This article uses a (very) simple blogging database consisting of three tables:


The following is the signature of our Blog table, as defined in the designer code behind of the generated DBML file Linq uses:

[Table(Name="dbo.Blog")]

public partial class Blog : INotifyPropertyChanging, INotifyPropertyChanged

{


Here is the same signature, after serialization has been enabled:

[Table(Name="dbo.Blog")]

[DataContract()]

public partial class Blog : INotifyPropertyChanging, INotifyPropertyChanged

{


Note the addition of an attribute, DataContract. This labels the class as Serializable. Most of the object’s properties have a similar addition. Here is the Blog’s title, before:


[Column(Storage="_Title", DbType="NVarChar(50) NOT NULL", CanBeNull=false)]

public string Title

{


And after:


[Column(Storage="_Title", DbType="NVarChar(50) NOT NULL", CanBeNull=false)]

[DataMember(Order=3)]

public string Title

{


Note the DataMember attribute. The Order parameter it takes in reflects the order of the columns in the database, and ensures that during serialization the properties will always end up in the same order they were in before.

Limitations of Unidirectional Serialization
Now, there are limitations to this solution. Serialization done here is unidirectional; it only goes one way. You cannot (easily) convert a serialized LINQ object back to its former self without losing some references. In other words, your objects won’t be able to make a round trip, so this solution will not work for services that require this. 
In fact, cycles are the main reason why this problem exists. If you look closely at the generated DBML again, you might notice that some properties are not marked with the DataMember attribute. To avoid a cyclical dependency issue in Xml serialization, LINQ will not label child to parent relationship properties as serializable. For example, the User object contains an EntitySet of Blogs, which is marked for serialization:


[Association(Name="User_Blog", Storage="_Blogs", OtherKey="UserId")]

[DataMember(Order=5, EmitDefaultValue=false)]

public EntitySet<Blog> Blogs

{


However, on the Blog object, its reference to the user does not:


[Association(Name="User_Blog", Storage="_User", ThisKey="UserId", IsForeignKey=true)]

public User User

{


So, when you serialize the Blog object, it won’t have any mention of a relation to the User.  The User object will have a list of related blogs, so you can maintain the relationship, but this problem cripples having bidirectional serialization without also forcing introduction of some serious processing overhead (which, in addition to the cyclical headache, is probably why it is not supported in .NET 3.5).

Conclusion
Unidirectional serialization has its problems, but can still prove quite useful. In my next article I will discuss a few ways to take advantage of serializable Linq objects using some helper classes Microsoft stuffed in the dark corners of System.Runtime.Serialization, and maybe I’ll throw in some LINQ to XML while I’m at it. Stay tuned.

Read and post comments | Send to a friend

An Inch of Dust

This may be a long post.

My earliest memories are of Super Mario Brothers, world 1-1, when I was about four years old. In my life, I have owned (in rough chronological order): an NES, a SNES, two Gameboys, a Sega Genesis, a CDX, a 32X, a Gameboy Pocket, a Nintendo 64, a Sony Playstation, two Gameboy Advances, one GameCube, a Nintendo DS and DS Lite, a PS2, an Xbox 360, a Wii, a PSP, around half a dozen PC's and four laptops since 1996 from an Intel 386 to the Athlon X2, and one Macintosh PowerPC for the express purpose of playing the Escape Velocity series.

I have owned nearly every installment of every major Nintendo IP ever released, excluding the Capcom Zeldas, a few of the Gameboy Mario's, and those other ones we do not speak of. I cut my RPG teeth on the SNES with FFIV and Super Mario RPG. There was time when I was in middle school where I would save up every dime of my allowance (roughly $11 a week depending on chores) specifically for N64 games like Jet Force Gemini, Rogue Squadron, and Super Smash Brothers. Among my GameCube library you'll find the likes of Eternal Darkness, Metroid Prime, and Beyond Good and Evil. Just to name a few. Hell, I even have oddball shit like DDR: Mario Mix. I have been a dedicated consumer of Nintendo for decades, now. Not necessarily because they are Nintendo, but because games on their consoles were always among the best ever made. I knew that I would have no trouble finding a few unquestionably masterful titles, no matter what Nintendo system it was on. Even the GameCube managed to keep that M.O.

But this time, it's different. We got our Zelda, our Mario, our Metroid. The first was basically a love letter to a legend, the second was pretty cool but nothing revolutionary, and the last was the only one of the three to really give a shit that it was on the Wii. But other than that, what is there? I own six Wii games and a few VC titles, and whenever I walk into a GameStop and look at the wall, the only things that interest me are remakes of last-gen stuff.

Here is where I'm conflicted. I understand and share the Nintendo fan’s view of what the Wii could be. Retro’s Metroid Prime 3 showed us what it can do. Nintendo, for the most part, has not. It's like coming home from a long summer vacation and visiting a friend who suddenly isn't interested in the same things anymore. Their conferences and press releases bore me. I don't care about Wii Fit. I don't want to take the time to punch in a billion different fucking numbers so I can play on a shitty overprotective online service, for a 'moderated' shadow of what was once my favorite fighting game series.

I suppose the largest disappointment for me is when I see examples of games that Nintendo now considers "for me." The latest was that trailer for Disaster: Day of Crisis.

I want to want it, believe me. The music sounds incredible, the story is delightfully in the same B-Movie vein as RE4 and Dead Rising, and it's about a guy running around saving people while a bunch of shit is flooding and blowing up. That all sounds awesome. The problem is in the execution. Every screenshot and video I've seen of this game looks, well, outdated. It doesn't look terrible, really, just grossly outclassed by everything else I care about this year.

All of this really boils down to something simple. Nintendo doesn't really compete with Microsoft or Sony anymore. They're doing their own thing, and they're doing it without me in mind. I get that. I'm ecstatic that they've pulled in the older generations; I love that my 78 year old grandma liked Wii Sports.

I just wish Nintendo was still blazing the trail, instead of focusing solely on making it wheelchair accessible.

Read and post comments | Send to a friend

Early Morning Rising

Greetings. It has (yet again) been a while.


In an effort to commit to joining the 'early bird' crowd I am, among other things, attempting to make a daily blog entry part of my morning routine. The general idea is to give me a reason other than work to get up in the morning, an idea inspired by this guy. We'll see how this goes.

Some changes have occurred. These days I am a partner (one of three) in a new company called Plaidian LLC, a name whose spelling no dictionary seems to know. I consider that a victory. Anyway, this venture is in many ways a successor to that of Systepic LLC, Curbside Studios, and the general idealogical soup before that. We write software. Any software. Our first significant work can be seen on a project partnered with Nemo DesignVoodooPC.com, specifically the Envy site. So far it has gone pretty well; business is picking up and the momentum shows no signs of falling off. It is possible (knock on wood) that my dreams of self-employment are finally paying off. About time.

Other than that, things are pretty much the same. I still reside in the western fringe of Portland, a location that is increasingly inconvenient. The average ride on Trimet takes over an hour and a half to get to our office in SE Portland. I have plans to move closer to, possibly within, downtown. I play games when I can, enjoy coffee, and sleep. 

Oh, and I have an iPhone now. Love that thing.

Read and post comments | Send to a friend

The Adventures of PC Gaming: Contempory Chronicles

God dammit. I broke Steam.

More specifically, my laptop froze while I was enjoying a round of Team Fortress 2 and now it won't let me play the game. If I start Steam and run TF2 it pops up the usual 'Preparing to launch' dialog and, after a brief bit of puffing, just disappears. If I try it again, a 'Verifiying game files' dialog pops up briefly, then melts away. Trying to get my game on from then...on...is just a repeat of the verification chronicled in the previous sentence. Restarting Steam results in a scene-for-scene retelling of the previous sentences.

I see a pattern. That pattern is plaid. And by plaid I mean this is probably why I don't play PC games much anymore.

Read and post comments | Send to a friend

Shiny, is it not?

Hey everyone, the new site I have been not-so-secretly working on is up. No more redirection to Vox! I will, however, continue posting from Vox, as the new site merely aggregates content from various RSS feeds. Expect new things to show up periodically, including an XNA section for my eventual foray into a series of how-to articles on the framework :). For now, I gotta run. The Coffee Crutch is closing and they're kicking me out!

Read and post comments | Send to a friend

From A Party to a Fish Market

I am posting from the 520 floating bridge to Seattle, on a King County Metro express bus. The bus has free mobile wifi; How awesome is that? The seats are far more comfortable than Trimet's, and the bus' appear to be on schedule far more reliably. To top it off, my fare was $1.25, instead of Trimet's $1.70 - $2.05. I wonder what they have that Portland doesn't? Sales tax, perhaps?

Anywho, I'm in the Seattle area doing grip work for a Microsoft party in Redmond. Apparently every year they hold a holiday party for the employees. This year it is taking place in the Building 42/43 parking structure. The whole thing has a really industrial vibe, with an elaborate set of trusses and LED's marking the entrance to half a dozen different color-coded hotspots. Most of the loungese will be bars, with one of them (purple I think) reserved for the catering. There will be four Xbox 360's in the Green Lounge.

I worked from 8pm-3am Tuesday and noon to 2am last night, for a total of 21 hours. Tonight I'll be working from 7pm to at least 3am tearing stuff down. The party itself apparently costs between $150,000-$200,000, and will be on from 2pm-6pm today. My mind spins at the thought of this. Two hundred grand for a four hour employee party? Incredible.

I'm in downtown Seattle now, have to get off soon. I'll post again sometime Friday, maybe with pictures of the place if my phone doesn't die on me again.

Read and post comments | Send to a friend

Coffee as a Crutch

I'm hanging out in downtown Portland today, at the wonderful little Coffee Crutch, just up Yamhill from Pioneer Square. Its just a dollar for a cup of coffee, and you can refill it for free. I imagine some of their business model revolves around one feeling guilty about such a deal and making up for it by purchasing a pack of Tic-Tacs or a muffin, which they leave conveniently on display. Tempting me.

In addition to the usual Systepic stuff, I am revisiting my work on Project Theta. It is interesting uncovering work one has done before; I rediscovered a bunch of OneNote entries I wrote almost a year ago, many of which I'd forgotten existed. I think I'm going to pick up where I left off, which means I'll have to hunt down my copy of Dante's Inferno again. Judging from my notes, I was somewhere in the middle of the 9th circle...

On the gaming side, I recently picked up Zelda: Phantom Hourglass for my DS, and am having an absolute blast with it. I was initially a bit worried when I read the game would work entirely off of the touchscreen, but as usual Nintendo quietly backhanded my doubts away within minutes of my first gesture. All in all, the game feels like a lighter, more to the point version of Wind Waker; the same look and feel, less text. The world appears smaller, though I've only uncovered half of the sea charts, and explored less than half of one of them. Unlike Wind Waker, which split the world into dozens of small postage stamp charts, the entire map is split into just four large ones. These are all just initial impressions, so take anything about the game's size with a good slab of salt.


Read and post comments | Send to a friend

About Portal The Streets of Portland & How Things Change

Greetings, world. I know, it has been ages since I graced Vox. There is much to explain.

For starters, I no longer call Salt Lake City my home. Matt and I decided that it was time to get out in the world and make a name for ourselves, so we have relocated to Portland, Oregon to found Systepic LLC. Our focus is industry-based penetration software, a method of development where we research what a business lacks in terms of software, and provide a solution to fill that need. I have written a much more detailed summary of what our company is about on the actual company website so if you are so inclined, feel free to check it out.

This of course means that I am no longer an active student at Neumont University. This is not the end, by any stretch; I fully intend on completing my degree. I just don't feel I need to do so right now. I have not 'dropped out' of college! To 'drop out' implies a general disinterest in the major, and a shift away from anything to do with it. Quite the opposite, I'm diving into the industry head first.

It has not been an easy run, getting settled out here. Initially we had a more stable source of funding and thought we would have a place in downtown Portland within two weeks of arrival. Now, it looks as though we'll be residing in Beaverton. It's not far from downtown, as Google Maps will show you. Also, there are a number of public transit options available that can land you right in Pioneer Courthouse Square for only a few dollars. This saves us hundreds on living expenses, as well. Still, I would have liked to be closer. The University District, ideally (good god is it expensive around there).

Portland has changed somewhat since I last frequented it, and not really for the better. Much of downtown is torn to hell due to construction for a new MAX Line. That's fine, but the crime rate in north Portland has spiked quite a bit because of it. There is a lot less car/walking traffic around Union Station, which has led to open air drug dealing, among other things. On 5th and Hoyt, where I used to hop a shuttle to and from Saint Helens back in my PCC days, one cannot cross the street without being...solicited. I truly hope that the situation improves once the construction is complete, but I'm no expert on how effective that will be.

A lengthy conversation with a Portland PD Sergeant revealed that a good deal of the trouble has something in common with irony. Apparently, whenever there is a spike in crime in an area, there is at first an equivilent spike in police reports called in by residents. However, as time goes on people stop reporting crimes, because they see them so frequently that it moves from extraordinary to commonplace. This doesn't help the local PD much, because their statistics show a drop, and less resources are allocated to help. It sounds like a pretty vicious cycle.

That's all for now, my laptop is running low and my steak soft taco is getting cold. By the way, the Yucatan Grill in Pioneer Shopping Center's food court is surprisingly tasty, for mall food.

Read and post comments | Send to a friend

The Purpose of a Party

I sometimes wonder if parties exist simply to sell more bottles of Pine-Sol.

Read and post comments | Send to a friend