locked
Best Practice - Solution structure when using the Entity Framework 4.0 RRS feed

  • Question

  • We are creating a web & mobile app. that consumes data via a set of web services. We would like to use the entity framework 4.0 as a part of our solution. 

    We typically split our Visual Studio solutions into a a number of projects representing the different layers (data, business, services, presentation) & utilities.

    This is the first time we are using the entity framework 4.0 and would like to know if there are any best practices as to Visual Studio Solution/Project structure and where the entity model should be best created?

    For example, should we have a separate Visual Studio project for the model or would it normally reside in a Visual Studio project reserved, for example, for data access? 

    We are also about to start looking into the new DAC project type. If we have a data-tier application component (DAC), can the entity framework be used to couple up to data via the DAC or maybe this does not give any real meaning?

    Wednesday, September 15, 2010 6:30 PM

Answers

  • On 9/15/2010 2:30 PM, IT Zynergy ApS wrote:
    > We are creating a web & mobile app. that consumes data via a set of web
    > services. We would like to use the entity framework 4.0 as a part of our
    > solution.
    >
    > We typically split our Visual Studio solutions into a a number of
    > projects representing the different layers (data, business, services,
    > presentation) & utilities.
    >
    > This is the first time we are using the entity framework 4.0 and would
    > like to know if there are any best practices as to Visual Studio
    > Solution/Project structure and where the entity model should be best
    > created?
    >
    > For example, should we have a separate Visual Studio project for the
    > model or would it normally reside in a Visual Studio project reserved,
    > for example, for data access?
    >
    > We are also about to start looking into the new DAC project type. If we
    > have a data-tier application component (DAC), can the entity framework
    > be used to couple up to data via the DAC or maybe this does not give any
    > real meaning?
    >
     
    The EF model should be part of the DAL. The service layer can be called
    by the BLL if you want, which in turn calls the DAL and the DAL
    interacts with the model.
     
    Or you can have the service layer call the BLL, the BLL calls the DAL
    and the DAL interacts with the model, but in this scenario, the BLL and
    DAL are folders, along with EF in one classlib project.
     
    Here are several solutions you can download to look at project structure
    in regards to how EF is used a layered architecture. You may want to
    look at the rest off the other code examples too. It's the only way to
    go if you have to come out of the gate fast.
     
    http://www.dofactory.com/Framework/Framework.aspx
     
     
     
     
    Thursday, September 16, 2010 1:44 AM
  • On 9/15/2010 2:30 PM, IT Zynergy ApS wrote:
     
    <snipped>
     
    Here are some other links you can use with you EF project.
     
    <http://msdn.microsoft.com/en-us/library/bb387145.aspx>
    <http://msdn.microsoft.com/en-us/library/bb387118.aspx>
    <http://msdn.microsoft.com/en-us/library/bb896240.aspx>
    <http://www.informit.com/articles/article.aspx?p=1273361&seqNum=3>
    <http://www.codeproject.com/KB/linq/LINQquery.aspx>
    <http://blogs.msdn.com/b/dsimmons/archive/2010/01/12/ef-merge-options-and-compiled-queries.aspx>
    <http://www.informit.com/articles/article.aspx?p=1273361&seqNum=3>
     
    Also, use a profiler like the SQL Server's Profiler to see the T-SQL
    being generated when using Linq-2-Entities with EF, which can result in
    slow queries if you're not aware of the T-SQL being generated to execute
    the query.
     
     
    Thursday, September 16, 2010 2:02 AM

All replies

  • On 9/15/2010 2:30 PM, IT Zynergy ApS wrote:
    > We are creating a web & mobile app. that consumes data via a set of web
    > services. We would like to use the entity framework 4.0 as a part of our
    > solution.
    >
    > We typically split our Visual Studio solutions into a a number of
    > projects representing the different layers (data, business, services,
    > presentation) & utilities.
    >
    > This is the first time we are using the entity framework 4.0 and would
    > like to know if there are any best practices as to Visual Studio
    > Solution/Project structure and where the entity model should be best
    > created?
    >
    > For example, should we have a separate Visual Studio project for the
    > model or would it normally reside in a Visual Studio project reserved,
    > for example, for data access?
    >
    > We are also about to start looking into the new DAC project type. If we
    > have a data-tier application component (DAC), can the entity framework
    > be used to couple up to data via the DAC or maybe this does not give any
    > real meaning?
    >
     
    The EF model should be part of the DAL. The service layer can be called
    by the BLL if you want, which in turn calls the DAL and the DAL
    interacts with the model.
     
    Or you can have the service layer call the BLL, the BLL calls the DAL
    and the DAL interacts with the model, but in this scenario, the BLL and
    DAL are folders, along with EF in one classlib project.
     
    Here are several solutions you can download to look at project structure
    in regards to how EF is used a layered architecture. You may want to
    look at the rest off the other code examples too. It's the only way to
    go if you have to come out of the gate fast.
     
    http://www.dofactory.com/Framework/Framework.aspx
     
     
     
     
    Thursday, September 16, 2010 1:44 AM
  • On 9/15/2010 2:30 PM, IT Zynergy ApS wrote:
     
    <snipped>
     
    Here are some other links you can use with you EF project.
     
    <http://msdn.microsoft.com/en-us/library/bb387145.aspx>
    <http://msdn.microsoft.com/en-us/library/bb387118.aspx>
    <http://msdn.microsoft.com/en-us/library/bb896240.aspx>
    <http://www.informit.com/articles/article.aspx?p=1273361&seqNum=3>
    <http://www.codeproject.com/KB/linq/LINQquery.aspx>
    <http://blogs.msdn.com/b/dsimmons/archive/2010/01/12/ef-merge-options-and-compiled-queries.aspx>
    <http://www.informit.com/articles/article.aspx?p=1273361&seqNum=3>
     
    Also, use a profiler like the SQL Server's Profiler to see the T-SQL
    being generated when using Linq-2-Entities with EF, which can result in
    slow queries if you're not aware of the T-SQL being generated to execute
    the query.
     
     
    Thursday, September 16, 2010 2:02 AM
  • Hi,

     

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 

     

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, September 20, 2010 1:21 AM
  • Hi Darnold92,

     

    Thank you for the very useful information and links - they have been a great help. 

    Best regards

    ITZ.

    Saturday, October 23, 2010 10:00 PM