EF 4.1 Code-first: Executing Stored Procedure
Since I worked in my company, I was required to learn a lot of stuffs. One of the basic things to learn was to adapt from my mostly used Java programming language to C#, along with the proper MVC platform.
Of course, .NET MVC, being a platform (for vocabulary nazis, I use the term architecture and platform interchangeably), it is obviously tightly integrated. This was the thing that I dislike the most with the .NET framework, you can’t have full control (to some extent) as to what you do. And then my opinion suddenly changed when I was introduced to entity framework, namely, their code-first approach. Code-first approach gives you that flexibility to meld the code behind as you like, it gives you full control (again, to some extent) of what you can do.
My post today will show you how to simply execute a stored procedure and retrieve the results back. This is supposed to be simple if you were using database-first or model-first approach. Otherwise, Entity Framework 4.1 does not support a complex type mapping for stored procedure in code-first approach (at least for now). See this post for more information on that fact.
/// <summary>
/// Function to call the stored procedure in the database.
/// </summary>
/// <param name="param1">A string containing the username.</param>
/// <param name="param2">A string containing the password.</param>
public Guid CallProc(string param1, string param2)
{
// Creating SqlParameters
// Note that although SqlParameterCollection class exists,
// it cannot be instantiated since it is an abstract class
var userName = new SqlParameter
{
DbType = DbType.String,
ParameterName = "UserName",
Value = param1
};
var password = new SqlParameter
{
DbType = DbType.String,
ParameterName = "Password",
Value = param2
};
// This is the "correct" query that will return an entity object.
// However since EF4.1 does not support a complex type mapping FOR
// stored procedures, this is rendered unusable (for now).
// return DbContext.Database.SqlQuery("FindUser @UserName, @Password",
// parameters).ToList();
// Returning the user ID (as Guid)
Guid userId = DbContext.Database.SqlQuery("EXEC FindUser @UserName, @Password",
param1, param2).SingleOrDefault();
return userId;
}
I have highlighted some of the important points in the code. Now, let’s start dissecting the code.
On line 6, this is your usual standard function in C#. Nothing special here, just a function taking two parameters and returning a Guid result. Please note that the function name does not have to be the same as the stored procedure name.
On line 13-15, we need to create SqlParameter, in order for the framework to translate the call to the correct data types. This also prevents SQL injection, and is actually a good practice. Like I have stated in the code, we can actually create SqlParameterCollection if we want to. For simplicity sake (and greater flexibility), we’ll just use the SqlParameter class.
The SqlParameter can take any supported data type. In the example, we used string, but we can also use Guid and other primitive data types. I have yet to use objects, however, I would have to assume that it is not supported.
On line 28-29, I have put the proper way to call and execute the stored procedure from within Entity Framework. However, it is not yet supported. In this commented code, I actually used SqlParameterCollection variable, parameters.
On line 32-33, is the actual call made by the framework to the database. This will call a stored procedure called FindUser, passes on two parameters (UserName and Password, respectively), and will return a Guid as the ID of the user.
Of course, it goes without saying that the database must have a stored procedure called FindUser which accepts two parameters, UserName, and Password as string or varchar. The stored procedure must also return Guid as a result. I have yet to use another data type, but in this case (using Guid as a return type) works.
So there you go. I admit this solution might not be the best solution, however it works for now. At least it solves the limitation of the EF 4.1 using the code-first approach. See you next post!
A Quick “Hello” Again
Hi there! It’s really been a very long time since I last updated the blog. I do have a couple of posts unpublished, but unfortunately I have not finished most of the posts, sadly.
In this post, I just want to say that I still consider this blog as something that I will write to regularly (eventually, but hey, I’m trying), so I guess I do deeply apologise for the lack of content in the last couple of months.
Down the track, I plan to include a new section focusing on code development, as you all know I AM a software developer. I believe this would help some of the developers out there if they were to encounter the same issue as I did.
I will also update other sections, so if any of you enjoyed visiting this blog, do not feel left out!
And last but not least, happy *cough* belated *cough* new year for you all. And I’ll see you next post!
Nintendo 3DS Launched in Australia
Hi guys. I actually was planning to write a post yesterday, but something came up. Yep, the official launch of the Nintendo 3DS in Australia. As most of you would already know about, Nintendo 3DS is the successor of the highly successful portable gaming console, Nintendo DS (and it’s subsequent rebrand of DS Lite, DSi and DSi XL), which by 2011, has sold more than millions of units, not counting the games. As a true avid gamer, I personally wanted the 3DS, not only because of its features, but also because Nintendo will ultimately move to 3DS anyway.
I got an invitation to the launch party in EB Games Swanston street. The launch party is held from 10PM on 30 March 2011, and by 12.01AM on 31 March 2011, they will roll out the 3DS units. I was actually expecting a massive line-up for the 3DS, but it seems that everyone just get their own number, and join the party. Oh yeah, when I say party, I mean party.
My queue number for picking up the 3DS
The Nintendo Experience booth on 2nd floor was packed
They do cater the people who came for the party. At the Nintendo Experience (2nd floor dedicated to Nintendo), there are lots of people, with balloons, games, and of course, the 3DS, complete with the babes, although the 3DS is not chained to them like they usually do. We also get served by a good catering, providing both savoury and sweet snacks like pies, cupcakes, and even Peking duck (or at least that’s what I heard)! I also met few cosplayers, one as Pikachu (I was VERY tempted to say “Can I peek-at-chyouuu?”), and the other one dressed as Link from the Zelda games!
Cupcakes! Most of the girls in the launch party had at least two of these
Link, complete with his her costume, shield, bow and sword
Ultimately we had to line up to pick up our consoles. And there was a door prize draw for winning a brand new Nintendo 3DS for FREE. I get my hopes up when they say the number, but I missed by 7 entries! Come on! The one who won the 3DS was, well, surprise, surprise, Link!
My Cosmos Black Nintendo 3DS. Yes, I still believe black is the new white.
Anyhow, since it was already past midnight, I had to go back and take some rest, since the next day I have to go to work. I did get a chance to play the 3DS before, though, and I have to tell you that, like what EB Games said, to believe it, you would have to see it. Except maybe, they forgot to put the word yourself. See you next post…!
jovee~
A Trip Home (Part 2)
Hi guys! A little while ago I posted about my trip home to Indonesia and holiday to China, along with my family. It was a good trip and I really enjoyed it. I needed to go back to Indonesia for the police and character check for applying for permanent residency in Australia. Of course, as I have stated in my previous post, I can do it in two ways, the official or unofficial way, by going back to Indonesia and take care of it, or having it done from here with some “help” from fellow Indonesians. It was a no-brainer to me, as I didn’t want to violate the law.
So I went back to Indonesia for taking care of that, and for holiday. My family planned to go to China, but you can see all those in the previous post. In this post, however, I will focus on the Indonesian trip, albeit with minimal pictures displayed.
I arrived in Medan, Indonesia, which is my hometown. A small, yet modern city, which is currently (as of 2011, I believe) the fourth largest city in Indonesia after Jakarta, Surabaya and Bandung. Now, despite the title of being the fourth largest, it is still a small town where you can go from one place to another with only 30 minutes maximum (unless you get caught in a mild traffic jam).
Telling the truth, I don’t quite like my hometown. It’s not as orderly as Australia, or even Surabaya and Jogja, and the humidity just soar through the roof. I had to change shirts every two hours or so. And not mentioning the people, so judgmental and not yet modernised. And both my parents know the fact that I don’t quite like being in Medan. The things that make me going back to Medan, are the fact that my family and my girlfriend’s family live there.
This time in Medan, I had the chance to meet two of my best mates, one of them currently live in Medan (he studied in the UK, though), and one of them studying in Kuala Lumpur. We hadn’t met for years, and it was such a pleasure to be able to meet them. I also asked my other friends to come by, but they couldn’t (with their obviously obvious reasons). I guess that’s what separates best mates from friends, huh?
I also had the chance to go to Surabaya and Jogja. Surabaya is the second largest city in Indonesia. It’s a mix of highly modern Jakarta, with some of the rural areas. It’s a very nice city to live in, and the people are very welcoming, much better than Medan. Unfortunately, though, I only had two days in Surabaya, as I had to go to Jogja.
Jogja is one of the largest cities in Indonesia, dubbed as the student’s city. Jogja is actually even smaller than Medan, as I can still remember most of the streets in Jogja, but the people in Jogja are very, very, very polite. Its traditional values are still kicking in, and they are given a status as a special administrative region called the Kesultanan (literally, kingdom).
My girlfriend and I planned to meet in Jogja for just 3 (yep, you read that right, THREE) days, along with my family, since my younger sister currently lives in Jogja along with my grandparents. We (me and my girlfriend) had a great time in Jogja as we went to Prambanan Temple. Here’s the picture of one of the Prambanan temples (and I believe this is the only picture I got from my Indonesian trip):
One of the temples in the Prambanan complex
I always find Jogjakarta (the longer name of Jogja) fascinating, as it manages to keep its traditional values in the midst of the modern world. We tried to go to the Keraton (which literally translates to palace), but it was closed because there were going to be a traditional ceremony called sekaten the next day. For you tourists, I would advise you to not only go to Bali when you go to Indonesia, but Jogja as well. It’s only roughly 2-hours flight from Bali anyways (and besides, it’s way cheaper than Bali).
So, all in all, my trip back home to Indonesia (and to China) was very enjoyable, to say the least. I had the chance to see my girlfriend, my family, and also made some trips I’ve never done before. My only regret was I didn’t take enough pictures to show it to you guys.
But anyways, I am currently playing Pokemon White version, as it was just released a week ago. Now, hopefully by next post I am able to post a review of this game. So until then, see you next post…!
jovee~
A Trip Home
It’s been some time since I last post here. Well, I was actually overseas for several weeks and had been back in Melbourne for few weeks as well. I’ve been looking for a job as well, and so far I only landed being a part-time employee in Swinburne University (which is great, in my opinion).
So today’s post is only a catch-up post on what’s been happening to me in the last few months. Obviously, I graduated at the end of 2010, and since I love living in Australia, the next logical step to do is to apply for permanent residency. For those who don’t know (or don’t even bother about it, or even didn’t know that it exist), it is a very time consuming (and money consuming, ya know, since time is money) process. There are a lot of legal documents to submit, and of course administration fees in the process. And they still could reject your residency if you were seen as unsuitable.
One of the legal documents that I need to submit, is a police clearance statement from every country that I’ve been living in the last 10 years. Obviously, my home country Indonesia is one of those countries. A little background to Indonesian bureaucracy culture, when there’s money there’s a way. Therefore I had two choices, to go the unofficial way by trying to arrange for my Indonesian police clearance to be sent here. Or I could go the official way by going back to Indonesia and take care of it. It’s a no brainer, really. I’m living at another country, and the last you would want is not to abide the law.
At any rate, my family also wanted me to go back, so there I was, going back to Indonesia. Although I won’t comment on the police clearance, there are a lot of things that I’ve gained during my short trip in Indonesia. So this is my trip home, back to my home country, my home town, and to some extent, my ancestor’s home in China (I’m a third-generation Chinese Indonesian).
My family planned a family holiday to Hong Kong, Shenzhen and Macau. Of course for me, I’ve never set foot outside Indonesia, Singapore, Penang (Malaysia) and Australia, and it would be great! I really wanted to see what’s happening in China, and see things for myself, since it was always my girlfriend who told me how things are going there.
So we went to Hong Kong for our first stop. If I could explain it, Hong Kong is a metropolitan city, much like Sydney, but it’s busier, more crowded, noisier, and of course, dirtier. I’m not saying that their air quality is bad, it’s still superior compared to Indonesia. But the streets are dirty, and well, in some places you could smell foul stench as well.
We didn’t get the chance to go to Disneyland Hong Kong, but we did go to Madame Tussaud’s Museum. Madame Tussaud’s Museum is a museum dedicated for wax figurines of many (and when I say many, there are LOTS) of public figures, both from eastern and western world. From Lady GaGa (yes, she’s there as well) to Ayumi Hamasaki, from Obama to Jackie Chan, they’re all there (at least their wax figurine are). I didn’t take a lot of pictures though, since my sister did almost all the photo-taking.
Wax figurine of Yao Ming, the tallest Chinese basketball athlete
at more than 2 metres height
Guess who? It’s William Shakespeare
The next destination was Shenzhen. Now a bit of geography, Shenzhen is located in southern China mainland, therefore it was not that cold when I got there (it was winter in the northern hemisphere). However, we went to a place called OCT East resort. It is a resort built on top of hills, with overall area of 9 kilometres. Yep, 9 kilometres of fun. And I have to tell you, it IS a beautiful and soothing place. I did take a lot of picture here because I like the scenery and the soothing nature of the place.
Believe it or not, this is already on top of a hill
This is the largest pumpkin in the world, weighing roughly 250kg
Unlike most resorts though, OCT is divided into several sections. From the two pictures above, it was the main entrance hill section, and the botanical gardens. There are also other sections themed individually such as wetlands, where you can see tropical fish, Christmas town, where everything is covered by (fake) snow, and some others. There’s even a fantasy-themed town, making you feel like you’re in Traverse Town or something.
The aforementioned fantasy-themed town, called Interlaken
On the back is the Interlaken Hotel, which will cost you
like probably HK$10,000 per night (unconfirmed)
To tell the truth, there’s so much you can do in only ONE day exploring OCT. In the end we didn’t get to explore all the three mountains (yes, it spanned across 9 km on top of hills, what do you expect?), but I can guarantee you that, should you have the chance to go to Shenzhen, by all means you have to drop by to OCT East. You won’t regret it.
Our next destination was Macau. For those of you who never heard of Macau, let me put it in a simple way: it’s the Las Vegas of the Asian world. People would come to Macau solely for gambling (not me and my family, though), and there are several big casinos in here like the MGM Grand, the Sands, and some other casino franchises. The biggest one is, the Venetian. Boasting more than 3000 rooms (at least that was what the tour guide said), this sort of mega-casino-mall-hotel combination is the main attraction in Macau. And their interior is designed like Venice, complete with the canal and waterways!
Attention: this is NOT Venice, this is the Venetian in Macau
The interior is decorated even with faux sky
Overall, I really enjoyed my trip home. It was pleasurable, enjoyable, and although I did get some rashes on my scalp (my girlfriend said China’s water is not that clean, so yeah), it was amazing. But my trip did not end there, for sure. I still had some time in Indonesia before I went back to Melbourne. However, considering this post is quite long now, I think I’ll have to postpone it, until the next post…!
jovee~
Review: Golden Sun: Dark Dawn
I’m an avid RPG gamer, and judging from the countless posts I’ve made mentioning this, I can assure you that. Lately, there’s only so much RPG games that you can play AND actually enjoy. The numbers are lower when it gets to traditional good ol’ RPG game. Things were a bit boring since I finished Dragon Quest IX, but then this game came out.
Golden Sun: Dark Dawn is the long awaited third instalment of the Golden Sun series. Obviously if you don’t play any handheld or portable games, you won’t know the series. But if you do, this series is the Final Fantasy for the handheld, minus all the complicated battle mechanics and technological weirdness.
The previous two games, Golden Sun and Golden Sun: The Lost Age was made for GameBoy Advance, and it was deemed to be the best RPG for handheld at the time, and refreshing as well. So after many speculations and couple of years, the sequel finally came out. Since I played the two original games, I decided to buy the sequel and see how the sequel live up to its series’ reputation. Bear with me as we stroll along a lengthy review.
Storyline
The game takes place in the concept of a flat world in which you can actually see the edge of the world falling off like waterfall. The world, called Weyard, comprises of several continents representing the real world continents.
The world of Weyard is being put together by four elements, Venus, Jupiter, Mars, and Mercury representing earth, wind, fire, and water, respectively. These four elements, collectively called alchemy, were once in abundant, however several hundred years ago, people who are able to manipulate these elements, called Adepts, sealed it off because they feared that the abuse of these elements would crush Weyard.
Continents of Angara (top) and Gondowan (lower left) as seen in Dark Dawn
Sadly, they were wrong. Since these four elements were the elements that held Weyard, the world started to crumble. Islands started falling off the edge of the world, and many bizarre occurrences in the world happened. So, the protagonists set off to initiate the Golden Sun event, the event in which all the elements are unsealed and returns alchemy to the world. You can guess that finally the protagonists were able to unseal the elements. But those are the story of the first two games.
Dark Dawn is set roughly 30 years after the Golden Sun event, in which the event itself, even though it brings the alchemy back to the world, still have after-effects because the world was cut off from it for so many years. The game took place around the upper continent of Angara (as a homage to the Eurasia continent). The protagonists now are the children of the first two games’ protagonists. You play as Matthew, a Venus adept (the games ALWAYS start with a Venus adept…), the son of Isaac in the previous games as he travel around the world for obtaining a key item called Roc Feather.
As you might have guessed, although the journey seems straightforward at the first time, the protagonists got sidetracked and were led to a number of events that lead to the Grave Eclipse, in which the moon overtakes the sun and darkness will overcome Weyard. It is now up to the protagonists to stop the Grave Eclipse.
The story of the game itself is your standard typical the-only-one-who-can-save-the-world, however it does have some interesting quirks. The game stayed true to the previous two games by having the same world, the same battle sequences, and even some of the bosses from the previous two. One of the antagonist from the previous games returned in this sequel, although the role that the antagonist played is still hazy (even though I finished the game).
The only drawback from the game is that it lacked depth, and the conversations between characters are too light-hearted for the overall storyline. It really was annoying reading the characters saying stuffs that are obviously obvious. There are also several points of no return in the game, so you do have to be very thorough when exploring to not miss anything.
The previous two games told the story from both the protagonists and the antagonists perspective, and I can’t help but judging from the shortness of the story, there might just be a sequel for this. There might just be.
Overall, I would give 7 out of 10.
Gameplay
What the Dark Dawn messed up in the story part, it made up in the gameplay part. As I have previously stated, you play as adepts, who can freely manipulate the elements to your advantage. This manipulation, called Psynergy is an essential element in the game. You can actually use your psynergies (in your so-called standard RPG games, these would be magic) in the game world to solve puzzles! Venus adepts can grow vines to reach places, Jupiter adepts can blow whirlwind to steer your raft, Mars adepts can parch water puddles to access new areas, and Mercury adepts can freeze the water puddles to serve as a stepping stone. And of course the number of psynergies are extended further in the game.
Using the Cold Snap psynergy to create ice pillars
And that is not all the main feature of the Golden Sun series. The next one is the Djinn mechanics (singular: Djinni). Djinn are the purest incarnation of an element, and therefore carry the strength and nature of the element. These Djinn can be set to an adept, and will alter the status, psynergy setup, and possibly the character class of the adept according to the nature of the element (for example, Venus Djinni will most likely boost the HP and Defense). There exists different ways of setting Djinn, and one can mix-and-match the elements to get the best line-up.
Djinn interface in Dark Dawn (Japanese)
And there’s more to the Djinn mechanics, the Djinn that are set to an adept can be called by that adept to use in battle, providing either offensive or defensive support. Sort of like magic as well. By calling out Djinn, you switch them from set to standby mode. The Djinn on standby mode can be again, called to conjure up various summons in the game. Think of the Djinn on standby mode as being in the pool where you can use them.
However, there is a drawback. Getting a Djinni into standby mode means that you will lose the any boost related to that Djinni, until you set it back to the adept. Furthermore, Djinn that already being used for summon go to recovery mode for several battle turns, before being set (luckily, they are set automatically) to the same adept again. This cycle of set-standby-recovery mode of Djinn is what made the gameplay so dynamic, as you do have to carefully plan whether you want to keep the boost, use the ability of the Djinni, or to use the powerful summons. Just for the note, there are 72 Djinn, and 30 summons in the game.
Eclipse summon in Dark Dawn (Japanese) requiring 3 Jupiter Djinn and 2 Mercury Djinn
There is also another yet overlooked mechanic that is similar, but yet different from most RPG games. Like RPG games, a character can equip weapons of certain types. There are two main stream of weapon in the game, the normal ones, which you can buy from the store, or artifacts, which you retrieved from the dungeons. Like any RPG games, there are also critical hits. In the case of normal weapons, you only get a normal critical hit. But in the case of artifacts, you get what the game called, unleash.
Megiddo unleash sequence in Dark Dawn (Japanese)
An unleash is basically an embedded magic inside the weapon, and you have no control over it, you can’t make the weapon unleash at any time you want, making the battle so interesting, because some unleash are so powerful (Megiddo, for example, guarantees 3x damage for single enemy), and some can be helpful (Psyphon Seal locks your enemy’s psynergy). Best of all, it does not require any magic points or whatsoever.
These game mechanics is what made the game so interesting and refreshing at the same time. And these mechanics are not new mechanics, meaning it was featured from the previous two games. In fact, these mechanics are exactly what differentiate the series from another RPG games. For being true and actually improving the standard mechanics, I give 9 out of 10.
Audio
Not like many other RPG, Dark Dawn did not include composer as great as the Final Fantasy series with Nobuo Uematsu. That, however, does not mean that it doesn’t have a great music. The battle music is pretty much suited with the pace, and the game world theme music is more than decent. I can’t really say much about the audio, because there is nothing special, however it is not bad either. For that reason I would give 6.5 out of 10.
Graphics
The graphics of Dark Dawn is surprisingly more than good. Now remember, this is a handheld game that I’m talking about, and it’s being developed for Nintendo DS. Therefore you would expect that the game would return into the old 2D style like they did in the previous games.
That, however, was not true because Dark Dawn uses a fully 3D rendered image, albeit viewed in a top-down perspective. The top DS screen is used for informational, such as the map, number of Djinn on standby, or even the status of the party, while the lower screen displays the game world in 3D. And the colour palette is also colourful enough, making the game world quite enjoyable in your eyes.
Exploring the Passaj Mountain Climb
I gotta say, the graphics is more than you call good. If you had your chance to play Dragon Quest IX, then the graphics would be slightly (albeit arguably) better than DQIX. Not only that, the battle sequence is rendered in 3D as well, with all the summon sequences and unleash sequences also rendered in 3D. You would think with all these 3D stuffs, the battle would be lengthy, but it’s not. In fact it’s quite fast, let’s just say that a normal battle that wiped out 4 monsters in one turn would take more or less 10-15 seconds, 20 seconds max.
For a more-than-stunning graphics (of course in regards of being a handheld DS game), I would give 8.5 out of 10.
Final Words
Dark Dawn is of course arguably one of the best classical RPG game. It differs from the traditional old-school RPG games by having a refreshing and interesting game mechanics, combined with the good graphics for a handheld game. Adding up the points, it would be 31 out of 40, and most of that points mainly goes for the game mechanics. This is surely one handheld game you don’t want to miss. And don’t worry if you don’t play the previous two games, Dark Dawn did a good job to fill you in with the details.
jovee~
Images courtesy of Golden Sun wiki and guide4gamers. You can find the guide as well on the guide4gamers site.
Happy New Year 2011
Hello again, guys. It’s been a week since New Year’s Eve, and how did the fireworks go? I just want to wish you a quick happy new year, and hopefully this year will bring more and more good stuffs around you.
For starters, I finished my degree (both bachelor and masters) last December, therefore I am currently looking for work. Hopefully I could get the kind of job that I want. And that’s not all, I’m currently applying for permanent residency for Australia. All the documents are ready, I just need to go back to my home country to get my police check and character clearance document, then I’m good to go.
Last December was quite busy for me, as I was working, and apart from that, I still have several activities that I had to attend to. But alas! I will post an update to that benchmark, although with Google Chrome going to version 8, I might just have to start all over again. It’s probably better if I just take a look on the release plan of the major versions of browser before I do my benchmark again…yep, I think that’s the way to go.
I am glad to welcome you back, faithful readers of my blog. I know, I know, I did not post as regularly as I should, but this year I made that one of my resolution. Neat, huh? For new readers, welcome to my sanctuary. This is my personal blog space containing mostly pieces of my mind, and some reviews (although mostly games and whatnot).
For next post, I will post a review about a game that I’ve been playing since new year, Golden Sun Dark Dawn. But anyways, I do hope you have a great year ahead of you, and I also hope that you enjoy my sanctuary as much as I enjoy writing it.
jovee~
Impressions