Skip to content

Instantly share code, notes, and snippets.

@sc68cal
Created December 8, 2011 20:38
Show Gist options
  • Save sc68cal/1448454 to your computer and use it in GitHub Desktop.
Save sc68cal/1448454 to your computer and use it in GitHub Desktop.
SDLC notes for Monday

Topic

The best way to design the business objects

Discussion

An ideal environment for creation of business applications 
should allow developers to describe the business logic and 
state of the problem domain which they are modeling with 
minimum or no "noise" coming from the underlying 
representation and the infrastructure that supports it. 
  • What are the underlying representations?

    • Relational Databases
    • XML/SOAP/JSON
  • What libraries and tools can be used to reduce the "noise" coming from these representations?

    • LINQ
    • ADO.NET Entity Framework
    • Object-Relational Mappers
  • What is LINQ?

The Language-INtegrated Query feature of .NET provides general-purpose query facilities for the .NET runtime, for use with many types of data, including XML, Relational Databases, as well as native data types (Collections, Sets, Arrays, etc...)

Using LINQ, programmers are not forced to switch into the languages of the underlying representations (SQL, XPath, etc), and then build layers of glue code to bring those representations back into the .NET runtime.

LINQ & EF example

// we'll use the order-tracking store
using(OrderTracking orderTracking = new OrderTracking()) {

    // find all the pending orders for sales people
    // in Washington
    var orders = from order in orderTracking.SalesOrders
                 where order.Status == "Pending Stock Verification" &&
                       order.SalesPerson.State == "WA"
                 select order;

    foreach(SalesOrder order in orders) {

        // obtain a list of StockAppProduct objects
        // to be used for validation
        List<StockAppProduct> products = new List<StockAppProduct>(
            from orderLine in order.Lines
            select new StockAppProduct {
                ProductID = orderLine.Product.ID,
                LocatorCode = ComputeLocatorCode(orderLine.Product)
            }
        );

        // make sure all products for this order
        // are in stock through the stock management
        // system
        if(StockApp.CheckAvailability(products)) {
            
            // mark the order as "shippable"
            order.Status = "Shippable";
        }
    }

    // if we marked one or more orders as shippable, persist
    // the changes in the store
    orderTracking.SaveChanges();
}

Sources

The ADO.NET Entity Framework

Entity Framework, LINQ and Model-First for the Oracle Database

Avoid the LINQ to SQL Data Objects vs. Business Objects Debate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment