开发者

Which ORM supports mapping existing databases?

So I have a layered ASP.NET MVC proof-of-concept application with good separation between presentation concerns, business logic, and infrastructure concerns. Right now it is operating off of a fake repository (i.e. LINQ queries against static IQueryable objects). I would like to create a functional SQL repository now.

That said, I don't want to simply tie it into a database that has a 1-1 mapping between tables and entities. That wouldn't meet the business need I am hoping to solve (partial integration with existing database - no hope for convention over co开发者_如何学Cnfiguration).

Do you have suggestions for which ORM / mapping tools I should consider and/or avoid?

Do you have suggestions for articles/books I could look at to help me approach this topic?

Would it be better to simply use parameterized queries in this scenario?


Entity Framework in version 4 would definitely allow you to:

  • have a mapping between the physical database schema and your conceptual schema, e.g. having an entity mapped to several tables, or several tables joined together forming a single business entity

  • grab data from views (instead of tables directly)

  • use stored procedures (where needed and appropriate) for INSERT, UPDATE, DELETE on every entity


NHibernate sounds like a good fit for what you are looking for. You will be able to make your repositories call queries in either HQL or using the API, either way you can get to your database and shape the data to fit the way your repository is being used. It will always be hard to make a square peg fit into a round hole though. SO has lots of nice support when you get into using NHibernate, good luck.


As you mentioned in the question, it is very debatable to choose an ORM. Different people will have different project needs. I am not exactly sure what will take priority for you. Here is what I have tried myself.

NHibernate seems to be the most commonly used ORM in DotNet projects. I feel it suffers from a typical open source problem. It offers so many features but the documentation really sucks. If you have lots of time at your disposal you can give it a shot.

Another options is to go for something like Entity Framework. Its very easy to set up and get up and running. With version 4.0 and the CTP there is provison for code first as well as fluent mapping and configuration. Since you have said you would want to keep the domain model separated EF 4 will help you because it has a notion of conceptual model which is an abstraction over the mapping layer.

You can refer to few links below for the blogs I had written based on my experience http://nileshgule.blogspot.com/2010/08/entity-framework-hello-world.html http://nileshgule.blogspot.com/2010/09/nhibernate-code-first-approach-with.html http://nileshgule.blogspot.com/2010/09/entity-framework-first-query-using.html http://nileshgule.blogspot.com/2010/09/entity-framework-learning-series.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜