Click here to Skip to main content
Click here to Skip to main content

Beyond the Entity Framework with DevForce

, 21 Aug 2012 CPOL
This article showcases where DevForce shines. DevForce relies on the Entity Framework for basic object mapping and query facilities, but provides so much more; including infrastructure for n-tier applications, powerful business objects, multiple data sources, and non-relational data sources.

Editorial Note

This article is in the Product Showcase section for our sponsors at CodeProject. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers.

The Microsoft ADO.NET Entity Framework (EF) has become the standard for database access in .NET applications. It is a robust object-relational mapping (ORM) solution that brings ORM to the mainstream and improves productivity and type safety with its use of LINQ (Language Integrated Query).

Of course there is much more to an application than how it handles raw data. There’s the business object layer that encapsulates and governs data with business rules and the layers that address application workflow and user experience.

Even if you concentrate only on data management, you’ll still find enterprise application requirements that Entity Framework can’t help with. Chief among them are:

  • N-tier, internet, and Silverlight support.

  • Proper support for a business object layer with business rules, validation, and MVVM decomposition.

  • Highly responsive client UI’s that exploit caching (and compression) to avoid redundant, slow trips across the network.

  • Centralized services, server-side events, and performance, scalability, and security.

  • Distributed transactions and entity models mapped to multiple data sources.

  • POCO support for mapping to non-relational data sources.

  • OData support for exposing entities to non-.NET applications.

Managing these requirements takes place outside of the Entity Framework. You can write the code yourself, or use a proven tool like DevForce to immediately save you time and prevent heartache down the road.

This is where a development tool like DevForce really shines. DevForce relies on the Entity Framework for basic object mapping and query facilities, but provides so much more.

Infrastructure for N-Tier Applications

The Entity Framework is intended for 2-tier deployments without any particular client scenarios in mind.

DevForce/image003.png

DevForce implements an end-to-end, n-tier architecture whose middle tier component is called the EntityServer. The EntityServer handles WCF requests from the client and shields the database from direct access from the internet. It is responsible for authorizing, validating, and executing client requests for querying and saving entities. It also handles other operations such as user authentication, subscription to server-side events, calls to custom service methods, and hosts other custom server-side logic (such as the creation of audit trails).

DevForce/image004.png

With DevForce, you don’t need to write a domain service to describe how to perform data-oriented operations. DevForce is fully integrated with the Entity Framework and already knows how to query, insert, update, and delete. All you need to do is copy the domain model to the server and everything just works.

Of course you can modify and extend the EntityServer if you’d like. You can:

  1. Inject custom behaviors in the Entity Service pipelines to add or change processing as when specifying operation authorizations or pre-processing entities to be saved.

  2. Enrich entity classes with custom business logic such as validation rules that DevForce recognizes and executes on the server.

  3. Add custom service methods that clients can call to perform arbitrary actions on the server.

  4. Subscribe to server-side events that notify a client when something of interest occurs.

  5. Replace certain DevForce components with alternative implementations.

Business Object Enhancements

The Entity Framework code generator produces entity classes that aren’t ready to be sent over the internet for presentation in a WPF or Silverlight UI. They lack serialization support, self-tracking, validation, and a host of other capabilities that are important in Rich Internet Applications (RIAs). DevForce enables your entities to go over the internet and gives you the power to quickly implement dynamic validation rules, calculations, state transformations, dynamic property interception and many other extensions.

DevForce replaces the Entity Framework default code generator and produces entity classes specifically designed for RIA scenarios. You’ll still use the Entity Framework’s EDM (Entity Data Model) Designer to define the conceptual model that drives code generation, but DevForce extends the EDM Designer to gather some extra information for code generation.

 [Bindable(true, BindingDirection.TwoWay)]
 [Editable(true)]
 [Display(Name="Company Name", AutoGenerateField=true)]
 [IbVal.StringLengthVerifier(MaxValue=40, IsRequired=true, 
     ErrorMessageResourceName="Customer_CompanyName")]
 [DataMember]
 public string CompanyName {
   get { return PropertyMetadata.CompanyName.GetValue(this); }
   set { PropertyMetadata.CompanyName.SetValue(this, value); }
 }

There are more attributes adorning the property than there are lines of code within it!

The attributes help the entity fulfill the multiple roles you want it to play on both client and server. Bindable, Editable, and Display are hints to UI tooling that affect how user controls are chosen and configured. The StringLengthVerifier is a validation rule derived from constraints expressed in the CSDL (Conceptual Schema Definition). DataMember is WCF markup indicating that the value of this property should be serialized.

You can alter or remove all of the attributes (except DataMember) by suppressing them in the EDM designer and by adding alternative annotations in a metadata buddy class.

The get and set implementations are one-liners that delegate to a member of the entity’s inner PropertyMetadata class.

   get { return PropertyMetadata.CompanyName.GetValue(this); }
   set { PropertyMetadata.CompanyName.SetValue(this, value); }

The property is relying on helper methods to perform functions that go beyond simple value access. In fact, each helper method establishes a property value pipeline—one going in and one going out—that can do more than access a backing field. The setter’s in-bound pipeline can intercept values, validate them, and raise events such as PropertyChanged. The getter’s out-bound pipeline allows the developer to intercept values on their way out.

Property interception, validation, and change notification are vital DevForce features that grant the developer fine-grained control over the behavior of an entity at the property level. The simple, one-line syntax conceals the potential for extending the property behavior with custom business logic—logic that might be part of the class definition or might be injected dynamically from sources outside the class.

Multiple Data Sources

The Entity Framework supports just one database per Entity Data Model. But many applications draw from data stored in multiple data sources. In DevForce, you can have a single EntityManager work with entities from multiple data sources. Saving back to these data sources is seamless as DevForce encapsulates all of the changes into a single distributed transaction if you’d like.

If you have the reverse problem—a database that is too large, you can use DevForce to break up a large database into multiple smaller models/modules that are easier to maintain and deploy. In Silverlight, DevForce also supports multi-XAP deployments so that you can minimize the amount of time it takes to launch the application, and only download additional modules as needed.

Non-Relational Data Sources

The Entity Framework can only map entities to relational databases, but DevForce's POCO (Plain Old CLR Object) support allows any data source that can be exposed as an enumeration to be used as a data source, which enables developers to work with a uniform, consistent object mode, regardless of the backing store.

DevForce can also expose the entity model as an OData service so that other non-.NET applications (like Java, Android, or iPhone/iPad) can work with (and even modify) your entities.

Conclusion

DevForce is a great choice for most RIA projects—just take a look at the advantages it provides. If you’d like to use DevForce to move beyond the Entity Framework, know that DevForce works best in combination with certain technologies and when working on projects with matching design and development goals.

  • .NET 4 on server (required)
  • WPF or Silverlight 4/5 client
  • Many screens for display and input of complex data
  • Entity-oriented architecture that queries and saves sets of related entities
  • Entity models with more than thirty entities
  • Entity Framework 4 to model entities and persist their data
  • Relational database supported by an EF provider as the primary data store

If the project you’re working on has similar requirements, you should absolutely give DevForce a look.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

johnlantz

United States United States
No Biography provided
Follow on   Twitter

Comments and Discussions

 
GeneralGreat Product PinmemberGregoryagu27-Sep-12 10:36 
BugPictures missing Pinmemberkof27911-Sep-12 4:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 21 Aug 2012
Article Copyright 2012 by johnlantz
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid