This topic is about the Business Object Model producer, it describes how to configure the producer to generate the business objects layer above the persistence layer.
You can use this producer to :
- generate .NET class for the entities declared in design model
- compile the generated class into .NET assemblies.
The Business Object Model producer ships with two sub-producers out-of-the-box:
- the Service Object Model Producer to generate the Service Object Model and the Smart Client Object Model layers
- the Object Model Cache Producer to add cache specific code to the methods of the generated .NET class.
![]() |
You must set the compile attribute to false if you want to disable the compilation step after the class generation step, this is particularly useful if you plan to create a class library project with Microsoft Visual Studio and compile with Microsoft Visual Studio, not CodeFluent. |
Example
This example demonstrates how to declare a Business Object Model producer configured for compiling an assembly CodeFluent.dll at the relative target path ..\Generated\Model
In the configuration node of the Business Object Model producer, the namespaceImports attribute is used to add the using System.Xml and using System.Data directives to the generated files, the targetProductionOptions attribute is used to group output files by namespace and by node type (entity, collection or enumeration), the reference node is used to add System.Core.dll at compilation time.
| XML | Copy Code |
|---|---|
<cf:project xmlns:cf="http://www.softfluent.com/codefluent/2005/1" defaultNamespace="CodeFluent"> <!-- Microsoft SQL Server Producer --> <cf:producer name="Microsoft SQL Server Producer" typeName="CodeFluent.Producers.SqlServer.SqlServerProducer, CodeFluent.Producers.SqlServer"> <cf:configuration connectionString="Server=localhost;Database=CodeFluent;Integrated Security=true" targetDirectory="..\Generated\Sql" /> </cf:producer> <!-- Business Objects Model Producer --> <cf:producer typeName="CodeFluent.Producers.CodeDom.CodeDomProducer, CodeFluent.Producers.CodeDom"> <cf:configuration compile="true" namespaceImports="System.Xml,System.Data" targetDirectory="..\Generated\Model" targetProductionOptions="GroupTypesPerDirectory|GroupSplitByNodeType" outputName="{0}.dll"> <reference>System.Core.dll</reference> </cf:configuration> </cf:producer> <!-- Entities --> <Customer> <Id /> <FirstName /> <LastName /> </Customer> </cf:project> |
|
Business Object Model Producer Output
For each entity, the BOM producer generates two business objects : one object for the entity and one object for the entity set.
You can notice that the producer has generated two class for the Customer entity :
- the Customer class with the properties Id, FirstName, LastName
- the CustomerCollection class with the properties Count and this[int index].
You can also notice that the two class have the same signature for the Insert, Save and Delete method. Fortunately, for the Load method, the signature is different : the Customer class has a Load method to load one entity and the CustomerCollection class has a LoadAll method to load all the entities.
| CSharp | Copy Code |
|---|---|
// Class Customer public class Customer { // Fields private string _firstName; private int _id; private string _lastName; // Methods [DataObjectMethod(DataObjectMethodType.Delete, true)] public static bool Delete(Customer customer); [DataObjectMethod(DataObjectMethodType.Insert, true)] public static bool Insert(Customer customer); [DataObjectMethod(DataObjectMethodType.Select, true)] public static Customer Load(int id); [DataObjectMethod(DataObjectMethodType.Select, true)] public static bool Save(Customer customer); // Properties [XmlElement(IsNullable=true, Type=typeof(string)), DefaultValue((string) null)] public string FirstName { get; set; } [DataObjectField(true), XmlElement(IsNullable=false, Type=typeof(int)), DefaultValue(-1)] public int Id { get; set; } [XmlElement(IsNullable=true, Type=typeof(string)), DefaultValue((string) null)] public string LastName { get; set; } } // Class CustomerCollection public class CustomerCollection { // Fields [NonSerialized] private List<Customer> _baseList; [NonSerialized] private Dictionary<int, Customer> _baseTable; // Methods [DataObjectMethod(DataObjectMethodType.Delete, true)] public static bool Delete(Customer customer); [DataObjectMethod(DataObjectMethodType.Insert, true)] public static bool Insert(Customer customer); [DataObjectMethod(DataObjectMethodType.Select, true)] public static CustomerCollection LoadAll(); [DataObjectMethod(DataObjectMethodType.Update, true)] public static bool Save(Customer customer); // Properties public virtual int Count { get; } public Customer this[int index] { get; set; } } |
|
Developer Guide
The Business Object Model
