(This is the third part of a three part evaluation I am doing on SoftFluent’s CodeFluent Entities. Please read part 1 and part 2 before reading this.)
At the end of part 2 I had built the OrderProcess solution. And as I mentioned there, it had generated the necessary SQL scripts in order to build the OrderProcess database in SQL Server. Here’s what my Solution Explorer looks like now:
Just because I’m a curious sort of guy I thought I’d take a look at one of the SQL Scripts that CodeFluent generated. Here’s some of the OrderProcess_tables.sql script (I’m ignoring the normal IF EXISTS() … DROP TABLE stuff which naturally precedes these CREATE TABLE definitions):
CREATE TABLE [dbo].[Order] (
[Order_Reference] [uniqueidentifier] NOT NULL,
[_trackLastWriteTime] [datetime] NOT NULL CONSTRAINT [DF_Ord__tc] DEFAULT (GETDATE()),
[_trackCreationTime] [datetime] NOT NULL CONSTRAINT [DF_Ord__tk] DEFAULT (GETDATE()),
[_trackLastWriteUser] [nvarchar] (64) NOT NULL,
[_trackCreationUser] [nvarchar] (64) NOT NULL,
[_rowVersion] [rowversion] NOT NULL,
CONSTRAINT [PK_Ord_Ord_Ord] PRIMARY KEY NONCLUSTERED
) ON [PRIMARY]
This looks pretty normal.
Building the solution also generated new classes in the class library project OrderProcess. Here’s what some of the Order.cs file looks like:
// This code was generated by a tool.
// Runtime Version:4.0.30319.34014
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// CodeFluent Entities generated (http://www.softfluent.com). Date: Tuesday, 16 December 2014 15:16.
[System.CodeDom.Compiler.GeneratedCodeAttribute("CodeFluent Entities", "1.0.61214.0796")]
public partial class Order : System.ICloneable, System.IComparable, System.IComparable<OrderProcess.Order>, CodeFluent.Runtime.ICodeFluentCollectionEntity<System.Guid>, System.ComponentModel.IDataErrorInfo, CodeFluent.Runtime.ICodeFluentMemberValidator, CodeFluent.Runtime.ICodeFluentSummaryValidator, System.IEquatable<OrderProcess.Order>
private bool _raisePropertyChangedEvents = true;
private CodeFluent.Runtime.CodeFluentEntityState _entityState;
private byte _rowVersion;
private System.Guid _reference = CodeFluentPersistence.DefaultGuidValue;
private OrderProcess.ProductCollection _products;
this._reference = System.Guid.NewGuid();
this._entityState = CodeFluent.Runtime.CodeFluentEntityState.Created;
public virtual bool RaisePropertyChangedEvents
this._raisePropertyChangedEvents = value;
//the rest of the code is left out, for brevity's sake
Again, this looks like what you’d expect.
Getting into SSMS you can see that it’s created the OrderProcess database for us. Here’s what my Object Explorer now looks like in SSSMS 2014:
At this point you’ve got a working API for any .NET project you’d need to add it to. The instructions for the tutorial uses a console app to illustrate how this can be done. Add a console app named OrderProcecss.ConsoleApp to the OrderProcess solution.
Next you’ll need to add a reference to the OrderProcess project, in the new console app OrderProcess.ConsoleApp project. Also you’ll have to add a reference to the CodeFluent runtime DLL (CodeFluent.Runtime.dll), which on my system I found in C:\Program Files (x86)\SoftFluent\CodeFluent\x64.
Then we’ll enter the following code into the console app’s Main() function:
static void Main(string args)
Product car = new Product();
car.Name = "Car";
car.Price = 15000.0;
ProductCollection products = ProductCollection.LoadAll();
foreach (var p in products)
Console.WriteLine("\n\r\n\rPress Enter to exit.");
You also have to add some configuration information to the console app’s configuration file. Within the <configuration> section add the following:
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<OrderProcess connectionString="server=LOCALHOST;database=OrderProcess;Trusted_Connection=true" />
(Just a word of advice, I misspelled “connectionString” and had a devil of a time finding that error until the SoftFluent technical support pointed out my mistake.) Once you’ve done making those changes, you can run the application. When I ran it this is what I got:
As you can see by this, the ID is a GUID, but Name and Price both have what I assigned to them within the main() function of the console app. It even lists the EntityState (Unchanged, in this case).
This concludes my evaluation of SoftFluent’s CodeFluent Entities via their getting started tutorial. I hope that you’ve found this helpful.