Search code examples
c#winformsdata-access-layer

DAL for Windows Service


I am in a process of writing a windows service which will read an XML file generated periodically and update a DB. I have generally seen a 3 tier architecture in web apps (Presentation, BL & DAL as class library). I have the following questions

  1. Should we follow the same approach for the desktop app/windows service?

  2. Do we need to create instance members for DAL class or should it be static?

  3. Is there any tool that can quickly generate the DAL layer for the mapped DB?

    Any guidance will be greatly appreciated.

Thanks.


Solution

  • You don't have to use LINQ, NHibertate or Entity. A lot of projects running on .NET 4.0 still use old fashioned ADO.NET.

    LINQ to SQL is not something to be proud of in your application. As for Entity Framework or NHibernate, those are ORM APIs and have their highly beneficial usage scenarios, but also have a steep learning curve, and are less efficient in performance than using inline queries or Stored Procedure (But offer a lot better extensibility and maintainability). Another benefit in using those ORM libraries is that you don't have to write SQL in most cases, but it can give you some headaches if you have complex scenarios. And you can use Entity Framework with .NET 3.5

    If you are comfortable with SQL and the project has not a big team allocated, there's nothing wrong at all with using inline queries or stored procedures. Or, if you like, you can use something like MyBatis, which puplates objects using reflection based on a provided XML file. (I think they have generation tools).

    So my opinion, if you have a big database, but don't expect complex queries, the cost of learning Entity Framework is justified. But if you have a small database but with complex queries, which are already written somewhere, it would be a huge mistake to use Entity or NHibernate...