Complex types and stored procedures

I like the idea of complex type. Sadly the designer didn’t supported complex types in EFv1/VS2008, although you could use it manually editing the model (it’s just a XML file). The designer in EFv2/VS2010 supports complex types (and you can use it also with EFv1, see this) hence it’s time to start really using these.

Unfortunately nothing is perfect. As far as you don’t wanna map some stored procedure result to collection of entities, then the designer will tell you, that it’s not supported. :( And Jeff Derstadt pointed in forum that this limitation will not be solved in RTM.

I’m using EFv4 in my current project and thanks to ability to map functions directly to LINQ functions via EdmFunction attribute I was able to to a lot of work via functions and queries created by EF itself. But I always feel a little bug in my head saying “What if you’ll need it later?”. Sure I can redo all back into direct properties, but if it’s close to the end of the project it’s pretty expensive to do it.

What a pity, I see complex types as a good concept, but I’m too careful to close myself the path with SPs.

Tags: ,

Connecting from iPhone to Firebird

During the Friday I realized, that I did a long time nothing with my iPhone & MonoTouch development environment and I should try something more challenging. As I’m still fighting with some good idea for real world test application and my UIs are looking weird, I decided to turn my attention not to iPhone app directly, but to MonoTouch capabilities.

As a true geek I decided to try to connect to Firebird from iPhone. Although, thinking about it, I’m trying to connect to Firebird (or make it work with) with various technologies (Astoria offline, Silverlight, etc.). Because .NET provider for Firebird is pure C# and we have Mono compatible build, I deduced that it should work with iPhone too.

Sure, it’s a nice challenge to whole MonoTouch stack, because the .NET provider is more about the code than about the application itself. And we’re using there a lot of different things that can go wrong or may not be available or compilable to native code. And I have to say, the guys behind MonoTouch did a great work (I still can’t believe it).

With couple of minor tweaks I was able to create application that connects from iPhone (simulator) through internet to Firebird server. Pure C#, no hacking or major problems.


Application connecting to Firebird server and showing the server version.

First I’m impressed how mature the MonoTouch is. Second I’m still trying think thru all the possibilities you have with this. With some work on UI you can deliver the same database oriented application to Windows Mobile and iPhone using the same business layer (sure some webservice approach would be better, but …).

Looks like it’s time to stop playing and get some serious test app done.

I’m wondering whether we should start providing build of .NET provider for Firebird for MonoTouch/iPhone, as we have for Compact Framework?

Tags: , , , , , ,

Interface Builder crash

I think the whole iPhone SDK knows I’m from the other side of the barricade. :D What else would explain the error I faced today after less than a minute when working in Interface Builder.

On the other hand I was brave enough to send the error report (as I was able to reproduce it quite easily), so maybe it’ll be fixed in next version. Good turn? Anyway sooner or later I’ll convince the machine that I’m not a bad guy.

Tags: ,

Be careful with “not” conditions and nulls in LINQ when querying databases

Today I seen a code with good chance of hard to find mysterious bugs. Let’s start with database table structure we’re going to use for demonstration.

create table NullTest(id int primary key, b bit);

insert into NullTest values (0, 1);
insert into NullTest values (1, 0);
insert into NullTest values (2, null);

If you now try to query this table via LINQ (i.e. LINQ to Entities) you may get surprising results.

foreach (var item in ent.NullTests.Where(x => x.b != true))
{
	Console.WriteLine(string.Format("ID: {0} \t B: {1}", item.id, item.b));
}
Console.WriteLine("===");
foreach (var item in ent.NullTests.AsEnumerable().Where(x => x.b != true))
{
	Console.WriteLine(string.Format("ID: {0} \t B: {1}", item.id, item.b));
}

If you run this code, you’ll get different results.

ID: 1    B: False
===
ID: 1    B: False
ID: 2    B:

What happened? Is the database engine doing something wrong? Or is there a bug in LINQ? Neither of those. In fact both results are correct. The second one (evaluated in .NET on client) is obvious why it’s as is. But what happened in processing of first one (evaluated on database side)? The devil is in NULL logic. Every operation with NULL results in NULL or false if it’s a boolean operation. And this exactly explains the inconsistent result. In .NET null != true is true but in databases it’s false (because of the NULL rules described above).

Thus if you’re writing LINQ query for database, although the impedance mismatch should be hidden from you when using LINQ, you need to take into account different NULL handling in database engines and in .NET (or any common programming language).

Remember the DBNull.Value? That was explicit solution for this “problem”.

Tags: , ,

Knetlik – konference o .NET

13. února 2010 (sobota) se koná zajímavá konference okolo .NETích témat s podtitulem “Bringing Good Software Architecture”. Registrace je dostupná na známém místě. Program pak naleznete na knetlik.cz.

A proč je to konference zajímavá. Kromě přirozeně kvalitních témat ;) je to jejich délka. Pouze neobvyklých 10 minut (+5 minut pro otázky). Předpoklad je, že posluchači udrží takto lépe pozornost a vstřebají více informací. A ty budou ještě vlastně hodně kondenzované, aby člověk něco smysluplného řekl a přitom se vešel do časového limitu. Těším se, až uvidím, jak to funguje (nebo taky ne).

Tags: , ,

Školení Firebird (3.)

Společně s Databázovým světem tu máme další Firebird školení. Více informací, včetně možnosti přihlášení na: http://www.dbsvet.cz/view.php?cisloclanku=2010012101.

Tags: ,

Extending IQueryable with superset method and StackOverflowException

Yesterday I was creating extension method for Skip for IQueryable. I needed to accept the nullable integer and if null just skip any processing. Something like this:

static IQueryable<T> Skip<T>(this IQueryable<T> resource, int? count)
{
	return (count.HasValue ? resource.Skip(count.Value) : resource);
}

I thought it will pick the int version from framework, because I’m calling it with int and not int?. And I was wrong, what my colleague uncovered moments later. How to solve it? I was not happy with method rename and I felt there’s a way.

Actually the solution is pretty easy. The original Skip is just extension method, right? So it’s in static class as static method. So I can call it with class definition as non-extension method and this this there will be no ambiguity. Voilà.

static IQueryable<T> Skip<T>(this IQueryable<T> resource, int? count)
{
	return (count.HasValue ? Queryable.Skip(resource, count.Value) : resource);
}

Synology disk power cable

I was recently upgrading my Synology NAS adding new disks and rebuilding RAID volume. And because I somewhere lost (I’m storing all these pieces, but once a time I feel I have too much of small cables, screws etc. and I do the cleanup :) ) the precise length SATA power and data cables I was screwed. The data cable is easy to buy, although the shortest one I was able to find in reasonably long time was 50cm length. Never mind, it will fit there, with or without using force.

The problem was the power cable. After some searching I realized that the connector on motherboard is actually same as was on floppy drives (did anybody seen floppy drive in last 5 years?). With this information it was little bit easier to find the cables and/or adapters. At the end I bought SATA power < -> molex, molex (M) < -> molex (F) + floppy adapter. It works nicely, and also fits the box.

Just wondering what I’ll do, when floppies will be absolutely dead. Maybe I should buy couple of these cables in advance. :D

Hope this helps somebody when looking for this cable for Synology NAS (maybe the new products have also new more up-to-date connectors).

Tags:

First touch at MonoTouch

Looks like I joined the prominent group of iPhone developers. Friend of mine, Meap, also experienced iPhone developer should be scared. This is what I did in almost no time.

OK, this application sucks, it’s doing nothing and looks … well looks how it looks. :D

But the interesting think is, that the application is “written” completely in C# using Mono and MonoTouch. On iPhone you can’t have JIT (because there’s no way to switch page from data to executable) at least now from my little knowledge. Thus you for IL you have to do AOT and that’s nice challenge. In fact that was the reason why I was trying the iPhone development with the MonoTouch.

The environment is completely different (I mean the “iPhone style of creating apps”) from i.e. Windows Mobile. I’m really looking forward to try new stuff not only with the iPhone environment but also with MonoTouch as it’s an interesting piece of code. God, tomorrow, there will be a punishment from friends in office as I’ve sworn to be absolutely not interested in iPhone (and still I am from users perspective), but the development turned this into a temptation (because of developer perspective).

Tags: , ,

That’s an installation…

Today I was installing iPhone SDK (in fact that’s first time I was installing something such big on Mac) and at the end of the installation the installer started optimizing system (yes, system) for installed software. :D Funny. Hopefully it was not creating new kernel. :) Just wondering, what would happen if this crashes…

OK, before all Mac-friendly people will kill me, I’ll make a simple statement. I’m not using Mac regularly and that’s why I sometimes found something funny and why I’m making fun of it (and because I’m Windows user ;) ).

Tags: ,

Directory.GetFiles moral

Oh yes. I have here another moral. And it’s not good for me, because it’s (again) described in documentation (but who reads it when there’s nice IntelliSense?). In my program ID3 renamer I have couple of custom IO operations. On of base method is for enumerating directory(ies) for all MP3 files. It’s based on Directory.GetFiles and few functions inside ID3 renamer need exact order of files. One of these functions is FreeDB search. When I was renaming files on my network share, it wasn’t finding anything. But when moving the directory to local drive everything was fine.

After some debugging I found, that the ordering of files from network share is different than from local drive. If you look to documentation you see:

The order of the returned file names is not guaranteed; use the Sort() method if a specific sort order is required.

Ahh, there’s your problem. :) Sadly enough, the ordering from local drive looks stable and it’s based on filename as expected. Thus in a lot of cases you’ll not smell that something may go wrong. But on non local drives (for me my NAS) you’ll hit this immediately.

Never mind, could be worse (my first shot was some bug in my “MP3File” class and that will be really bad, as it could break users’ files). This can be fixed easily.

Tags: ,

Čechy v Kindlu

Když jsem předevčírem psal o naustálém rozrůstání nabídky novin pro Kindle a přáním, aby se vydavatelství u nás také zapojila do “kindle kolotoče”, ani jsem netušil co dnes objevím.

The Prague Post je k dispozici pro Kindle. Stále jsou to sice anglicky psané noviny. Ne masové jako třeba lidovky, ale každý malý krok se počítá.

Tags: ,

Switching from one CPU to more CPUs on XP

As I recently switched from Virtual PC to VMWare Workstation I wanted to upgrade my VMs to be able to use all cores I have and I granted. Machines I’m using most are Windows XPs and Windows 7. As the Windows 7 migration failed and I’m still about to install fresh W7 RTM, the challenge was XP.

Couple of hints I found on internet and as replies to my question in mailing list but nothing was working or it was screwing the system. But then I found a great document, with the manual, forced, way of switching. Although the document recommends doing the surgery in safe mode, I did it in live system (vivat snapshots) once, with just raw copy (+overwrite) and it worked.

copy C:\Windows\ServicePackFiles\i386\halmacpi.dll C:\Windows\system32\HAL.DLL
copy C:\Windows\ServicePackFiles\i386\ntkrnlmp.exe C:\Windows\system32\ntoskrnl.exe
copy C:\Windows\ServicePackFiles\i386\ntkrpamp.exe C:\Windows\system32\ntkrnlpa.exe

Anyway, on real important system I would recommend safe mode too. After reboot the system detected new hardware, installed it and after another reboot I was ready to make the cores screaming.

Tags: ,

Kindle, dějiství třetí

Nový firmware už je na světě chvilku a tak si dovolím jej trochu zhodnotit. ;) Prvně baterie. Subjektivně se výdrž opravdu prodloužila. S vypnutou sítí jsem nemusel více jak měsíc nabíjet (naposledy před konferencí v Mnichově až do včerejška, kdy ale baterie zdaleka nebyla prázdná) a čtu vlastně každý den. Pro mě naprostá paráda. Dříve Kindle připojím k počítači, abych něco nahrál, než že mu dojde baterka.

Přímá podpora pro zobrazení PDF je fajn, ale jde o trochu rozporuplnou funkci, alespoň nyní. PDF je předně formát pro popis zobrazení, takže pro zařízení zaměřené na obsah trošku problém. Na výšku, pokud nejsou písmena opravdu velká, je čtení nepohodlné (pro mě) – asi jako nejmenší písmo, které Kindle nabízí. Na šířku je to v pohodě, avšak hůře se “otáčí” stránky. Pokud bych měl v PDF knížku s jednoduchou sazbou, žádné boxy s tipy apod. raději bych si ji nechal převést. Ale pro programátorské knížky je přímé použití PDF lepší. Doufám, že v příští verzi firmwaru bude možné aspoň zvětšit font (klidně i nějaký default).

Vzhledem k jednoduchosti nákupu knížek je to jako nemoc. Bez rozmyšlení kupuju a hlavně čtu tituly, které bych normálně nekoupil, resp. se nad koupí dlouho rozmýšlel. Hodně pomáhá ukázka zdarma. A návrhy, které Amazon nabízí, jsou (ne)překvapivě dobře odpovídají mému gustu (ať žije data mining a “velký bratr”). Už jsem tak našel absolutně nové tituly, které mne zaujaly. Jediný problém je v Kindlu samotném. Pěkná sbírka pečlivě vybrané kvalitní literatury v knihovně vypadá dobře, ale pár milimetrů tlustá placka a jinak prázdná knihovna ne. ;) Holt něco za něco.

A kromě toho integrace se slovníkem (implicitně The New Oxford American Dictionary) je prostě úžasná. Jednoduchá, funkční. Nenásilně a podvědomě se člověk učí nová slovíčka. Paráda.

Asi nemusím připomínat, že 99% věcí v nabídce Kindle Storu je anglicky psaných. Nicméně třeba nabídka ne-USA novin znatelně roste. Doufejme, že i vydavatelství z Čech se zapojí. Mimochodem, pokud titul není pro Kindle dostupný, leč je v papírové verzi dostupný, je doporučeno “prudit” v diskuzi. Odezvy jsou, údajně, předávány vydavatelstvím, které následně mohou Kindle verzi schválit.

Tags:

Quick Search renamed to Navigate To

In March I wrote about one of the new features in Visual Studio, time being called Quick Search. If you look into VS2010 Beta 2 (current latest) you may be confused as there’s no function called like that. Now it’s called Navigate To. Luckily the shortcut is untouched – Ctrl+,. So if you wanna give it a try, look for this new name (or use the good old shortcut).

Tags:

Developers and Microsoft Surface …

What will happen when you put couple of developers during the conference in front of Surface? Yes first couple of minutes they will be trying to find a way to plug in keyboard and see what’s inside and how to make it crash as fast as possible. We did the same on recent MS Fest. After discovering nothing cool and just rebooting it we tested hardware limits. Putting as much fingers as possible and available. After collecting roughly 60 fingers and Surface still nicely working, tracking all and showing all the info, we gave up and started playing with it. Sure, some highly technical and logical game :D :

Yep, in every developer there’s a child (and in us maybe two) who wants to play.

Tags:

Jak jsme jeli na MS Fest

Před týdnem, joj to to letí, se konala akce MS Fest. S překvapivým množstvím přednášejících z Brna, konkrétně pět. Někoho, z této bandy napadlo zeptat se MS, jestli by nebylo možné uhradit nějaké ubytování, neboť akce začínala v 9 ráno, kluci od serverů měli tři servery, takže i když nebyl (myslím) nikdo první, stejně to chtělo přípravu. Tedy to znamenalo určitě před 6 vyjet z Brna (a mít čas všechny posbírat) – pro geeky kritický čas. :) A MS souhlasil. Pozn.: MS Fest je organizován MSPs (Microsoft Student Partners), hlavně z MFF UK, nikoli MS, ten pouze přispívá.

Jako ubytování byl zajištěn přímo od MS „Hostel Strahov“, což jsou napřímo řečeno koleje. Po zběžném obhlédnutí obrázku nic nevypadalo hrozivě, tak proč ne. Ovšem páteční příjezd kolem 11 večerní se rázem ukázal jako krásné prozření. Fotky dostupné na internetu byly pravděpodobně byt správce nebo tak něco. Blok 12, který nám byl přidělen, nabízel komfortní dvoulůžáky se sociálním zařízením na chodbě, pečlivě vybraným smradem a matracemi, na které se většina z nás bála položit i tašku s notebookem (nicméně povlečené, včetně mýdla a ručníku na polštáři :) ). Nedostupnost sociálního zařízení na pokoji, poměrně právem, rozlítila kolegu Petra Kaletu, neb on již den před tím absolvoval večerní předávání Křišťálové lupy a měl už jednu noc mimo domácí postel za sebou. Matrace poněkud nevyhovovali některým velmi (mě), jiným méně. A smrad otravoval všechny. :)

Po vzájemné dohodě jsme se rozhodli „apartmány“ opustit a najít něco za více než „dvěstěpade“ na osobu a rozumně se vyspat. Bohužel najít v předvánoční čas v pátek po 11 hodině v Praze volný hotel není tak jednoduché. Po asi 60 telefonátech (fakticky já a Kamil Roman jsme téměř konstantně jeden hledal a druhý telefonoval), kdy některé byly přímo vyprodané, jiné údajně taky, i když spíše to vypadalo, že takto pozdě nechtějí vyplňovat „papíry“, jsme uznali, že najít hotel ve tři ráno je fajn, ale jaksi postrádá ideu rozumného vyspání. Chtělo to plán B. Trn z paty nám vytrhl Michal Bláha, resp. jeho devmasterovská kancelář. S jeho svolením jsme v kanceláři strávili noc s hromadou energetických nápojů, baget a trochou spánku. No s tím spánkem to nebylo tak žhavé, ale aspoň byla legrace. Tímto bych mu chtěl za nás všechny poděkovat, za jeho dobrý skutek.

Ranní startovací kofein a mohli jsme začít. Večerní D1 jsme přežili všichni ve zdraví, neusnul jsem. Poučení? Pro příště nenavštěvovat „Hostel Strahov“ a nebo si zajistit něco sám. I v tomto čase v Praze (v předstihu) se za přibližně dvojnásobek „naší“ ceny dá najít útulný hotel nedaleko centra včetně snídaně.

Tags: ,

Mysterious problem when fetching data

Sometimes you’re talking about something on trainings and conferences and … and you simply forgot about it when you use it – it’s like being able to think in A > B way but not B > A.

This time it’s about views in Entity Framework. If you add a view into your model, it’s likely it will have a wrong key set up. Or maybe it’ll be missing. And because if two records have same EntityKey, they are considered same, also skipping the very expensive materialization. I added one view into my model and didn’t check the key. It was working fine, until last week, when the application started behave “differently”. I checked the database and view was providing proper data. Fetching was just reading from this view, no other processing. After some serious debugging and getting wrong data, in my case all records had same values as the first one. When I switched the projection it was good. I started to think about blaming EF. And I was wrong, sorry guys in EF team. The reason was, as you might guess, wrong key setted up. My view has a key composed from three columns, but only one was used. This caused the EF during the materialization to skip other rows, because the first column was same, thus getting wrong results. Fixing the key solved the problem immediately. It’s more embarrassing because if you look into the XML file, there’s comment telling you to check the key, because the inferred one can be wrong.

Anyway, now I know also the B > A way, which is even better as it was my personal experience.

Tags:

Photos from FBCon 09 München

Starter for (but not only) morning:

Holger Klemt:

Stefan Heymann doing the same as me:

Dmitry Yemanov:

Vlad Khorsun:

Roman Rokytskyy:

In between sessions:

During session:

In between sessions:

Everybody is solving problems during conference:

Talking about (not only) Firebird in hallways:

Tags: , ,

New firmware (2.3) for Kindle

This morning I looked to my RSSs and found post from Scott Hanselman about new firmware for Kindle. Although Scott was applying it manually, I got it through network immediately. After about 3 minutes Kindle rebooted and was ready to work.

You can read about the new features on Amazon page, I was especially looking forward to build-in PDF reader. Right now I tested only two or three files, all displayed correctly. But you can’t change font size, so if the font is too small in PDF, you will read nothing. With new screen rotation it’s little bit better, but the page will not fit display completely, of course, so you’ll be hitting next page button more. ;)

The battery life I can judge now. But anything that improves the batter life, even 1%, is good.

Tags: