I was working on a personal project today, and did a lot of experiments on Code First Model with Entity Framework. All of these were quite amazing and revealed a lot of underlying implementation and how things have progressed in Entity Framework world. I looked at various articles which helped me understand all these aspects, and am grateful of all of them. So I thought why not write some posts of mine too, just to document what I have learned, so that others might benefit from it too.
For that purpose I am starting with a simplest item, I will try to generate a database for a single class, and see how it looks. By the way I am using Entity Framework 5.
Here is the class, which I will work on.
Today I was helping on a project which was using ADO.NET SQL Client. Wow, it looks so much scary, and old. I was asked to do some tweaks, so that data layer could be organized. Can I use Repository pattern here, one of the ways to add separation of responsibility these days.
So I started on creating a base class for these repositories. I thought of managing all connection related code in that base class. That was quite easy when I moved ExecuteNonQuery related calls here. Next came the hardest part ExecuteReader, how to send back DataReader without loosing control on my connection state. I can not move all reader related usage in base class, that would negate single responsibility rule.
Hmm, one way would be to create a virtual method in base class, and then each inherited class can override and implement it’s own mapping rules in it. I did small test with that, but soon was struck, what about mapping compositions. If I used this approach then I will have to add multiple conditional cases to map each item properly.
Then I thought of passing in mapper related methods as delegate, not bad. But why not use new concepts, Action<T, T …> / Func<T, …, TResult> / Predicate<T, …, bool>.
Installing any application is not a hard part, but preparing your system for that installation takes some time and considerations. While installing Foundation today, I had the same issue myself. I did not know which pre-requisites should be installed first. I searched for it, and found different combinations, but one told me to run the pre-requisite installer first, it will let you know what are missing for you. Here are those which were required on my machine.
For some you will have to look for the specific download for your operating system (x86 / x64).
I downloaded and installed them, and was able to proceed next. By the way, did I mentioned that I am using Windows Server 2008 R2 Standard with Service Pack 1.
UPDATE: I found a PowerShell script for downloading all these pre-requisites, grab it from here, it might be handy too. http://gallery.technet.microsoft.com/office/bcf3332d-f726-4ac7-b01a-eeda4b7ece8e
We are working on a client application, which required to access data from SharePoint too. The best way to do that is to consume webservices exposed by SharePoint. While consuming them, we wanted to make sure which services are available in which version. We tried to find any matrix for that, but could not find one. So I thought of building it myself, so that others can reference it.
Today we had a very rough day, one of us had created a WCF REST service, and other one was trying to consume it in his IOS application, but he was not getting the correct response. We tested that call using Fiddler, could not find any problem in that. We tried very hard to troubleshoot why was that happening, but no luck.
We enabled WCF trace and message logging, although we could not log the actual message body, but we were able to review the headers of both calls. We found several differences other than the user-agent, and we experimented with most of them.
In my previous post I wrote about the simplest way of specifying logging location, which limited the solution only to environment variables set on a particular machine. However if you wanted to expand on all types of special folders available in Windows then we will have to look for a different solution, fortunately support for that is also available within log4net.
Difficulty level of this solution is a bit high, but it provides nearly 60 locations to choose from, as it uses “Environment.SpecialFolder” enumeration.
In one of our application we are using apache log4net, initially we were logging to the “logs” folder, which was located in the application installation folder. When we were testing this application on different Windows operating systems, it was not generating logs when we ran our application under least privileges account.
Where should we log then?
In my previous post I was trying to format date, and I noticed that I was not getting it correctly. Why was that, I assembled a small script to test all accessor methods provided by Date. Here is that code.
var today = new Date();
var message = "All accessor methods of date \n\n\n" +
"getDate(): " + today.getDate() + "\n" +
"getDay(): " + today.getDay() + "\n" +
"getFullYear(): " + today.getFullYear() + "\n" +
"getHours(): " + today.getHours() + "\n" +
"getMilliseconds(): " + today.getMilliseconds() + "\n" +
"getMinutes(): " + today.getMinutes() + "\n" +
"getMonth(): " + today.getMonth() + "\n" +
"getSeconds(): " + today.getSeconds() + "\n" +
"getTime(): " + today.getTime() + "\n" +
"getTimezoneOffset(): " + today.getTimezoneOffset() + "\n" +
"getUTCDate(): " + today.getUTCDate() + "\n" +
"getUTCDay(): " + today.getUTCDay() + "\n" +
"getUTCFullYear(): " + today.getUTCFullYear() + "\n" +
"getUTCHours(): " + today.getUTCHours() + "\n" +
"getUTCMilliseconds(): " + today.getUTCMilliseconds() + "\n" +
"getUTCMinutes(): " + today.getUTCMinutes() + "\n" +
"getUTCMonth(): " + today.getUTCMonth() + "\n" +
"getUTCSeconds(): " + today.getUTCSeconds() + "\n" +
"getYear(): " + today.getYear() + "\n" +
"toDateString(): " + today.toDateString() + "\n" +
"toGMTString(): " + today.toGMTString() + "\n" +
"toLocaleDateString(): " + today.toLocaleDateString() + "\n" +
"toLocaleString(): " + today.toLocaleString() + "\n" +
"toString(): " + today.toString() + "\n" +
"toTimeString(): " + today.toTimeString() + "\n" +
"toUTCString(): " + today.toUTCString();
Then I started experimenting, which is how I learn small things. unusual results:
- string is not a date
- conversion to date is not easy on my format (mm/dd/yyyy)
- formatting a date on a particular format is not easy too
So looked around, I found Datejs, which I did not wanted to use, as my task was not so much complex. Then I found some other good resources, who helped me complete this tasks.