Dev303: Leap Ahead in Productivity with LINQ & Entity Framework<br />Ronald Widha @RonaldWidhaTeam Lead<br />Infusion Deve...
Required Slide<br />Complete an evaluation on CommNet and enter to win an HTC HD2!<br />
Agenda<br />Pattern #1: Smart Client<br />Pattern #2: 3 Tier Architecture<br />Domain Driven Design<br />Pattern #3: Domai...
Presentation Tier<br />Data<br />Smart Client<br />
Presentation Tier<br />Business        <br />Data<br />3 Tier Architecture<br />
Demo: RAD and 3 Tier<br />
Domain Driven Design<br />“an approach to developing software for complex needs by deeply connecting the implementation to...
Domain Driven Design<br />Tackling complexity<br />How:<br />Talk to the business!<br />Focus on the core business domain ...
The concept<br />Entity & Value Objects<br />Aggregate Roots<br />Repositories<br />Value Objects<br />Value Objects<br />...
Keep it in sync with reality<br />Business rules change: REFACTOR!<br />Names change: REFACTOR!<br />
Presentation Tier<br />Business        <br />Data<br />Domain Models<br />
Linq to Sql<br />Isn’t flexible enough for domain modelling<br />1-1 table mapping<br />Table per Hierarchy<br />No provid...
Entity Data Model<br />An abstract conceptual model of data<br />Based on Entity Relationship Model by Dr. Peter Chen (197...
The Entity Framework 4<br />The next layer up in the ADO.Net stack<br />First product to implement EDM<br />Entity Data Mo...
Demo: Domain Driven approach using Entity Framework<br />
Full control<br />Just basic POCO: Plain Old CLR Objects<br />Persistence Ignorance<br />Turn off code generation from EDM...
Demo: Domain Driven approach using Entity Framework POCO<br />
POCO and Other EF Features<br />Different ways of mapping: Table per class, Table per type, Table per hierarchy<br />Mappi...
Code-only design<br />No model<br />Metadata is inferred from classes<br />Convention by Default<br />Configuration<br />T...
Last Notes<br />Don’t take the demo as best practice<br />There are a lot more to Domain Driven Design that what’s shown h...
question & answer<br />
Upcoming SlideShare
Loading in …5
×

Dev303 Leap In Productivity With Linq And Entity Framework 4

2,524 views
2,449 views

Published on

For TechEd ME attendees:
DEV 303, wednesday 11am Dubai C

One might ask, how can one be even more productive than with a DataGrid bounded with a DataSource? Is it even possible?

It sure is possible! To me, being productive doesn’t just mean starting fast, but keeping a sustainable pace as things get more complex. This is what true productivity is all about.

We’ll look at the evolution of design from Smart UI type of architecture (Rapid Application Development), 3 tier (Transaction Scripts) to Domain Driven design with rich domain models with behaviors. I will introduce the first few examples using Linq to SQL, and will take it to the finish line using the upcoming Entity Framework 4 and its POCO support.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,524
On SlideShare
0
From Embeds
0
Number of Embeds
85
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Hi My name is Ronald Widha, team lead, infusionTwitterPlease don’t forget to fill up the assessment sheet, I’d love your feedback, especially praisesWelcome to “Leap Ahead in Productivity with Linq &amp; Entity Framework”This a 300 level (advanced) talk, which assume you have some knowledge on entity framework, and general data access patterns
  • So I’m sure all of you have built applications which interacts with database beforeSo leap in productivityHow can you be more productive than thisPerfect for rapid application developmentBut is it really productive?Productivity to me is more than just starting fastBut also to keep the same pace as the project goes more and more complex
  • You have heard thisPresentation tierBusiness tier: these managers and services focused on the use cases. The implementation of the methods are normally calls to the data tierData tier: which in turn talks to the infrastructureIt’s data centric applicationA smart guy name Martin Fowler calls this: Transaction scripts.Because the business tier consists of transactional procedural script
  • Each of the managers are reusableObject oriented? Yes Manager/Services are objectsWe have the data encapsulated as objectsBut why isn’t the behaviors of the object get attached to the object itself.For e.g I want to be able to say ron.friends.add(photographer)Without the behavior, photographer camera objects are just data wrappersWhat’s wrong with that?Throughout time, as business rules gets more complicated, these rules will be scattered everywhereAgain, our focus is to get productivity by Managing complexity
  • What is it?2 books talks about this: Martin Fowler introduced the concept in his bookEric Evans covers the detail on How domain modelling can and should be done
  • Tackling complexityHow?Talk to the businessGet the core business domain knowledge and apply that to the design of your applicationTry and get rid of any impedance mismatch between how the business view a problem,With how we the engineers solve the problem
  • So again we want to focus on the domain. So we look for ways to represent these concepts in our system designEntity: an object in the domain model that is identified by its id. E.g same name, different id, different personValue objects: an object that doesn’t have any ID, and solely identified by its characteristics e.g if 2 address objects are the sameRepositories: a way to retreive entitiesAggregate roots: We want to be able to navigate from one entity to the nextPhotographer.cameras iterate through all the cameras owned by the photographerthe root entity where everything else is related to. The only one that has repositoryI have an address, I have a job, I’m speaking in a conference. Therefore I’m the aggregate root
  • UI, Business Tier, Data AccessDomain Objects business objects with have behaviors You should be able to navigate from one domain objects to another by accessing its propertiesIt’s no longer data centric, you care about the business concepts. The domain knowledge
  • 1-1 table mapping: doesn’t provide a flexible domain modellingCan’t hide the join table for the many to many relationshipOnce you have inheritance, it gets even trickier, linq to sql only support table per hierarchyAll that parent, child objects need to be stored into 1 tableNo provider model: if you don’t use sql server, you’re out of luckIt’s excellent tool for writng data centric application, but when you’re doing domain modell, you’re starting to push it to its limitsAnd if you don’t use any object relational mapping framework like linq to sql, and use t-sql, boy, it’s hard!-------Abstract concept above the data: entityRing a bell? Entities?It has relationshipsIt has navigation properties.What does that mean: you can navigate from parent entity to the childIf I want to get my camera’s manufacturer name, I don’t do inner joins between relational tableI don’t write queries using linq with where clausesWith navigation properties: Photographer.camera.manufacturer.name
  • - Next layer up above data- It implements the Entity Data Model concept, which is compatible with Domain Driven mentalityIt has full design tools, and the experience is as rich as Linq to SQLIt has linq capabilitiesCan handle different kinds of mappings to the database, not just 1-1You can hide that join table if you wanted toYou can have differnet kinds of inheritance modelTable per hierarchy, table per type, table per classIf you want to know more you can talk to me afterwards at the speakers lounge
  • At this point you might ask what is the difference between Entity Framework and Linq to SQLYes you can have more flexible mapping, but it’s still tightly coupled right?
  • So this is the cool thing, unlike linq to sql, the class is all in your control.You can create Entities using just POCO: Plain Old CLR objects, in other words: normal .net object without any framework specific base classesThis is also known as Persistence IgnoranceEntities should not know about the infrastructure/databaseIt is just a domain model and that is it. Nothing more.The idea is, you should be able to switch between Entity Framework to any other data access technology if you want to.How to do that, turn off the code generationSo you have full control over the classThe mapping between the object and the EDMX will be based on conventionIt tries to match the property name with the model namePOCO Generatorhttp://visualstudiogallery.msdn.microsoft.com/en-us/23df0450-5677-4926-96cc-173d02752313
  • Just like linq to sql, you can force to fetch related objects manually for optimizationJust like linq to sql, you can also leave it up to query related objects as it neededLoading the photographer class, will not have to load all the cameras until they are neededAll you have to do is mark the properties as virtualThe way it works, it replaces the property with a proxy class at runtimeSimilar way to how Nhibernate does it.Custom mapping, mapping with stored proc
  • Before we end the session, I want you to check out the code only designIf you’re a hardcore code junky like me, and don’t like using the mouseDon’t care about the database and want to fully ignore the persistence layerEverything is convention basedIt uses the name of the property and match it with the column nameYou can tweak it as you go alongOn runtime you can check if the database existIf it’s not,You can just generate the database from the classA similar approach to Azure storage approach (for those who attended Tuesday’s session of Windows Azure). Check if table exist, create if it doesn’t
  • Access session recordings at tech ed onlineMore videos about entity frameworkPDC09 walkthrough upcoming Entity Framework 4 featuresTwitterDon’t forget to fill up your Evaluation sheet
  • Dev303 Leap In Productivity With Linq And Entity Framework 4

    1. 1. Dev303: Leap Ahead in Productivity with LINQ & Entity Framework<br />Ronald Widha @RonaldWidhaTeam Lead<br />Infusion Development<br />
    2. 2. Required Slide<br />Complete an evaluation on CommNet and enter to win an HTC HD2!<br />
    3. 3. Agenda<br />Pattern #1: Smart Client<br />Pattern #2: 3 Tier Architecture<br />Domain Driven Design<br />Pattern #3: Domain Modelling<br />Entity Data Model<br />Entity Framework 4<br />Entity Framework 4 cool features (POCO, code only)<br />
    4. 4. Presentation Tier<br />Data<br />Smart Client<br />
    5. 5. Presentation Tier<br />Business <br />Data<br />3 Tier Architecture<br />
    6. 6. Demo: RAD and 3 Tier<br />
    7. 7. Domain Driven Design<br />“an approach to developing software for complex needs by deeply connecting the implementation to an evolving model of the core business concepts.”<br />
    8. 8. Domain Driven Design<br />Tackling complexity<br />How:<br />Talk to the business!<br />Focus on the core business domain <br />Design system based on a model<br />
    9. 9. The concept<br />Entity & Value Objects<br />Aggregate Roots<br />Repositories<br />Value Objects<br />Value Objects<br />Repository<br />Aggregate Root<br />Entity<br />Entity<br />Value Objects<br />
    10. 10. Keep it in sync with reality<br />Business rules change: REFACTOR!<br />Names change: REFACTOR!<br />
    11. 11. Presentation Tier<br />Business <br />Data<br />Domain Models<br />
    12. 12. Linq to Sql<br />Isn’t flexible enough for domain modelling<br />1-1 table mapping<br />Table per Hierarchy<br />No provider model<br />Awesome for data access<br />
    13. 13. Entity Data Model<br />An abstract conceptual model of data<br />Based on Entity Relationship Model by Dr. Peter Chen (1976)<br />Entities and Relationships<br />Entity types<br />Association types<br />Navigation properties<br />Sounds familiar??<br />
    14. 14. The Entity Framework 4<br />The next layer up in the ADO.Net stack<br />First product to implement EDM<br />Entity Data Model design tools<br />Strongly typed LINQ access<br />Declarative mapping to the database<br />The next version to Entity Framework 1 from .Net 3.5<br />Available in .Net 4.0<br />
    15. 15. Demo: Domain Driven approach using Entity Framework<br />
    16. 16. Full control<br />Just basic POCO: Plain Old CLR Objects<br />Persistence Ignorance<br />Turn off code generation from EDMX<br />
    17. 17. Demo: Domain Driven approach using Entity Framework POCO<br />
    18. 18. POCO and Other EF Features<br />Different ways of mapping: Table per class, Table per type, Table per hierarchy<br />Mapping with stored procedures<br />Explicit Loading<br />ObjectContext.LoadProperty(someObject, x => x.property)<br />Lazy Loading<br />Property as virtual<br />Uses proxy instance at runtime<br />
    19. 19. Code-only design<br />No model<br />Metadata is inferred from classes<br />Convention by Default<br />Configuration<br />Tweak configuration<br />Create database at runtime<br />
    20. 20. Last Notes<br />Don’t take the demo as best practice<br />There are a lot more to Domain Driven Design that what’s shown here<br />There are a lot more we can do to improve the demo code (Unit of work!)<br />EF4 is perfect to enable Domain Driven approach<br />
    21. 21. question & answer<br />
    22. 22. Required Slide<br />Speakers, <br />TechEd 2010 is not producing <br />a DVD. Please announce that <br />attendees can access session <br />recordings at TechEd Online. <br />www.microsoft.com/teched<br />Sessions On-Demand & Community<br />www.microsoft.com/learning<br />Microsoft Certification & Training Resources<br />http://microsoft.com/technet<br />Resources for IT Professionals<br />Twitter @RonaldWidha<br />http://blogs.msdn.com/adonet/<br />Resources for Developers<br />Resources<br />

    ×