We have created a new shiny assembly which is used in multiple applications. We regularly update this assembly, and add small new features in it. We want to minimize impact of these regular updates in installed projects, best option for us is to deploy it in GAC. Our regular installs were great, and never had any problems.
Mapping single class with a table was bit easy and fun. Next should be mapping associations, first I will try to map a simple one, using our existing application code. A person can have multiple email addresses.
So here is the modified code for person
In my previous post I generated a database without any mapping or customization, I got what Entity Framework could coerce from my class. Look at the schema which was generated.
Let’s see what I did not like about this.
- table name is not what I like to have
- Id was not marked as identity column, so no auto generation for this column
- all alphanumeric columns are created using nvarchar(MAX) which is not good too
- and the last, I wanted to use only date for birthdate not datetime
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>.
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?
I like Google’s suggest feature and was thinking of using it in any of my project. ASP.NET’s AJAX Control Toolkit have a similar control (AutoCompleteExtender) which provides a basic items to complete this functionality. I searched about its usage, and found many examples, but I was not satisfied with them. They all were populating only a single field using this extender.
I then came up with an idea, why not fill a contacts detail including its name, email address, and phone numbers using just one extender, but without modifying any provided functionality, so that our code be used with newer versions. Below is what it will look after populating that contact form.