Showing posts with label Microsoft. Show all posts
Showing posts with label Microsoft. Show all posts

Saturday, 4 February 2012

Entity Framework

With the beta version of Entity Framework 4.3 already in play, we can expect more fabulous things from Microsoft. If you haven't heard about Microsoft's Entity Framework, then it's probably alright. I sincerely mean it, even if you are a C# developer who manipulates objects controlled by the database.

The Entity Framework comes in three awesome flavours, namely Database-First, Model-First, and Code-First. I've never experimented with Model-First, but I've dabbled with the Database-First and Code-First types. Having said that, I wouldn't say I'm a pro at Entity Framework, because there are just so many things to consider when using the Entity Framework. A few of them would be...

  • Concurrency. There's just this evil exception known as the OptimisticConcurrencyException. Eat that, optimists.
  • Performance. Believe it or not, I've read that Entity Framework performance is far worse than running basic SQL queries. One can precompile his queries, and cache his results, but I'm nowhere near that level as of yet.
  • Flattening. This has less to do with EF, and more to do do with LINQ. Because we usually manipulate the results of Entity Framework using LINQ queries, problems can crop up when you're using Anonymous Types... Believe me, I've been there, and done that.

These are probably obstacles that a pro would never face. Having said that, let's have a quick run-through of the three awesome flavours of EF that Microsoft has to offer:

  • Database-First. As the name implies, you start off by defining your database schema and creating your respective tables using SQL Server. After that, you generate a .edmx file automatically using Visual Studio's Entity Data Model wizard.
  • Model-First. No database, no code (no guarantee either, because I have not tried this). You use the visual designer to define your models, with their respective properties, and the Framework helps you by generating the code and database.
  • Code-First. Write your own classes, create a DbContext class, and dump all your classes into it in the form of DbSets. When you first use your DbContext, EF automatically generates the database for you.

I must admit that the names can be a little confusing at first glance. Looking at it from another perspective, the equivalent of entity would probably be object. The three flavours only differ in the way you define these entities: whether you create them as database tables, draw them out using a given tool, or approach the code straight on. They all work, just that you will have more control on the approach in which you take.

Let's then approach LINQ. Take for example, you have a list of entities (equivalent of a table in a database) known as Employees. In code, you would probably approach it this way when you wish to retrieve a certain portion of them:
var selectedEmployees = from e in db.Employees

where e.Selected == true

select e;
The three most important keywords in a LINQ query would probably be from, where and select. Probably a little different from the usual SQL syntax, but that's how LINQ works (I think it was formatted this way because of how IntelliSense functions). There is another way to write LINQ queries though, and I find this way classier.
var selectedEmployees = db.Employees

.Select(e => e.Selected == true);
You would concur that it's classier, wouldn't you? ;) These expressions also allow you to access a wide variety of methods (e.g. .Where(), .SingleOrDefault(), etc.), and personally I think it looks neater!

Having said all that, I wouldn't say that EF is a fabulously beautiful concept. Old school SQL queries are, in my opinion, still good to use. There are some things that I dislike, though—one of which would be WCF Data Services being more accessible to EF. I mean, WCF is good and all, but why limit its functionality? I might not be right, but I have a hunch that this is Microsoft's way of pushing Entity Framework, to see that they achieve a remarkable ROI from the hard work they've put in for EF.

Anyway, good night to you. We are all human in the eyes of God (if there is a God), all entities from the perspective of a database, and all gold mines to Micro$oft.

Friday, 9 December 2011

Thoughts on IT

I went for my first interview yesterday. It was with Microsoft.



OK, I wouldn't say it's really my first, because I've had interviews before this. None of them, however, was about a complete evaluation of me—in other words, those interviews were nothing more than formalities. In this case, however, I had my qualifications looked at, I was observed, interrogated, and came out thoroughly disheartened.

It was an interview for an internship position, anyway. A position that went along the lines of developing proof-of-concepts for both aZaaS and Microsoft (in other words, whatever that I was going to work on was a shared project between aZaaS and Microsoft).

My main flaw of the entire interview, was, perhaps, being a little too humble (on hindsight), and also not being able to show my drive and willingness to go the extra mile. To be honest, I'm not exactly the very self-motivated, passionate-about-IT kind of student. I'm more of the, "I know you know I'm good", "We'll see with time" kind of person. I don't know. It's probably got to do with my personality rather than anything else.

Knowledge-wise, I believe I portrayed myself as a person who has a sound knowledge of whatever I've studied before. On the other hand, one of the interviewers' (there were two: a male and a female) questions stumped me. "What do you look forward to when you wake up every morning?" God, hath you forsaken me? I know not the answer to this question!

The male interviewer was the one who spoke the most, and he mentioned that he was working as a janitor. Someone who cleans stuff, stacks up chair... yeah, a janitor being an interviewer?! My frigging ass! I could only look at him in disbelief, thinking about what he could really mean. I think I must have looked really dumb there... So the interview gradually developed into a casual conversation that went along the lines of this... I can't remember the interview word for word, but, here goes:

He: So what do you look forward to when you wake up every morning?
Me: *speechless for awhile* Um, I think I'll need some time to think about it.
He: *smiles* By some time do you mean a few minutes, or a few years?
(I never came up with the answer in the end. Later...)
He: What do you know about ASP.NET?
Me: *ramble about GET, POST, Toolbox stuff, and Entity Framework* I used the database-first approach (referring to Entity Framework).
He: So what's the advantage of using the database-first approach?Me: Erm, I wouldn't say that there's really an advantage of a database-first approach, it's just the one I used when I developed it for the assignment. In the code-first approach, you write the classes first, but in the database-first approach you make the tables first. I guess the only difference is that you have control of the one you start doing first.
He: You know, during the first 5 minutes of the interview, you came across as a bo-chap person. But right now you show that you actually have knowledge of what you're doing.
Me: *feel proud inside*
He: What's stopping you from just going out there and making it big?
Me: Well, I don't really feel like I can make anything tangible. You know, when I was in secondary school, I picked up this book on C++; I'm not too sure whether C# was around at that time.
He: Yes, it was. I'm 10 years older than you.
Me: Oh, OK. Erm... yeah, and anyway, I learnt how to like assign an integer and stuff, but I never saw how I could make something tangible. I mean, even in school, we do assignments and make something out of it, but I never see any of them go into the market.
He: *something alone the lines of But you've never really tried, have you? How would you know?*

So yeah, it went something along the lines of that. I don't think I impressed either of them at the very least, but at the end of the day I hope I get the job! It might really be the "play hard-to-get" kind of thing that people in relationships do, just to tease us internship interviewees, but... I don't know! To cut it short, it was a very unnerving experience. At the same time, it was eye-opening; I learnt a lot from it.

On the other hand, my friend (who went in before me) portrayed himself as a true blue leader, a person who is very motivated and driven, willing to learn... But the questions the male interviewer posed (once again) shook him. Questions such as "what is the difference between mutable and transmutable?""what is an interface?", and "what is the fundamental difference between C# and Java?" I could probably talk some crap about the first two questions, but maybe not so for the third. I guess, I'm not really experienced at Java.

Overall, I'm glad that I came across naturally, and I tried my first real interview with who I really am; I did not, in any way, try to portray a false persona! this is one thing I'm really happy about. On the other hand, I have no idea if I'd get the job... oh well! Good luck to me.