ASP.NET and Entity Framework in Layered Architecture - using Entity Framework for ORM only

后端 未结 6 1491
庸人自扰
庸人自扰 2021-01-30 05:19

I have an ASP.NET application that uses a layered architecture e.g. presentation layer, business logic layer, data access layer.

I don\'t want to the business layer to h

相关标签:
6条回答
  • 2021-01-30 05:59

    Even if you use generated POCO classes, like the other ops are suggesting, you will still have to maintain a certain dependency to entity framework: the queries that you send to your DbContext / ObjectContext. Therefore you should consider encapsulating the queries in repositories.

    0 讨论(0)
  • 2021-01-30 06:09

    Now with the new EF4 you can also use POCO classes, thus removing the extra load of mapping the entities between layers. In our application we used EF4 and used business entities across the application other than view which required viewmodel. It gave significant performance boost.

    0 讨论(0)
  • 2021-01-30 06:11

    I suspect that this may be the answer to your problem:

    http://code.msdn.microsoft.com/EFPocoAdapter/Release/ProjectReleases.aspx?ReleaseId=1580

    The tool generates classes that have no entity framework dependency that you can pass across tiers.

    0 讨论(0)
  • 2021-01-30 06:15

    Not with entity framework, but I had tried to create a sample with two insert stored procedures being executed separately in the data access layer(using data access application block 3.1), wrapped inside TransactionScope context in Service/BLL, it did not work. One insert passed, other one failed and data WAS commited.

    Did you have any success doing this yourself?

    0 讨论(0)
  • 2021-01-30 06:19
    1. If you are practical: Yes! It will avoid you double mapping work and the potential errors generated by the double mapping. (By double mapping I mean DB -> ORM and ORM -> Business logic).
    2. Use TransactionScope. It's the best way to do transaction without worrying about nested transactions.
    0 讨论(0)
  • 2021-01-30 06:21

    Another way to do this is to use mapper classes, use what EF purely as data access and use the classes EF generated only within the DAL, then map these DAL objects to your BLL's objects through mappers. It works fine for us.

    0 讨论(0)
提交回复
热议问题