Beginner LINQ to SQL N-Tier Architecture Part 2
Friday, March 6th, 2009 by Daryl NunnIn Part 1 I created a dbml file and I’ll be using this as a DAL in the following examples.
In Part 2 I will be creating the Business Objects.
When creating business objects I often find that your BO’s (DTO’s) would mostly match your db, but BO’s are a logical way of grouping your data and not specific to how it is stored in the db, in most cases tho, it will be the same.
Create a new class, I place these classes under the Business Objects folder just to keep things organised.
Use the prop code snippet within Visual Studio 2008
Product Class:
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AdventureWorks.Business_Objects
{
public class product
{
public int? productId { get; set; }
public string name { get; set; }
public string productNumber { get; set; }
public bool makeFlag { get; set; }
public bool finishedGoodsFlag { get; set; }
public string? color { get; set; }
public int safetyStockLevel { get; set; }
public int reorderPoint { get; set; }
public decimal standardCost { get; set; }
public decimal listPrice { get; set; }
public string? size { get; set; }
public char? sizeUnitMeasureCode { get; set; }
public char? weightUnitMeasureCode { get; set; }
public decimal? weight { get; set; }
public int daysToManufacture { get; set; }
public char? productLine { get; set; }
public char? _class { get; set; }
public char? style { get; set; }
public int? productSubcategory { get; set; }
public int? productModelId { get; set; }
public DateTime sellStartDate { get; set; }
public DateTime? sellEndDate { get; set; }
public DateTime? discontinuedDate { get; set; }
public Guid rowGuid { get; set; }
public DateTime modifiedDate { get; set; }
}
}
ProductSubcategory Class:
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AdventureWorks.Business_Objects
{
public class productSubcategory
{
public int? productSubcategoryId { get; set; }
public int? productCategorId { get; set; }
public string name { get; set; }
public Guid rowGuid { get; set; }
public DateTime modifiedDate { get; set; }
}
}
ProductCategory Class:
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AdventureWorks.Business_Objects
{
public class productCategory
{
public int? productCategoryId { get; set; }
public string name { get; set; }
public Guid rowGuid { get; set; }
public DateTime modifiedDate { get; set; }
}
}
As you can see I have included all the properties for each corresponding table, this isn’t necessary of course, only include properties that you require in your App.
Once your Business Objects have been created we can then move onto creating the Business Logic Layer that will hold all the data retrieval code.
In Part 3 I’ll be showing you how to create the BLL for Products.


