Evaluation of CodeFluent – Part 3

(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:

Solution Explorer after the build

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
 (
  [Order_Reference]
 ) 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:

//------------------------------------------------------------------------------
// <auto-generated>
//     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.
// </auto-generated>
//------------------------------------------------------------------------------
namespace OrderProcess
{
    using CodeFluent.Runtime;
    using CodeFluent.Runtime.Utilities;
    
    
    // CodeFluent Entities generated (http://www.softfluent.com). Date: Tuesday, 16 December 2014 15:16.
    // Build:1.0.61214.0796
    [System.CodeDom.Compiler.GeneratedCodeAttribute("CodeFluent Entities", "1.0.61214.0796")]
    [System.SerializableAttribute()]
    [System.ComponentModel.DataObjectAttribute()]
    [System.Diagnostics.DebuggerDisplayAttribute("EK={EntityKey}, Reference={Reference}")]
    [System.ComponentModel.TypeConverterAttribute(typeof(CodeFluent.Runtime.Design.NameTypeConverter))]
    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;
        
        [System.NonSerializedAttribute()]
        private OrderProcess.ProductCollection _products;
        
        public Order()
        {
            this._reference = System.Guid.NewGuid();
            this._entityState = CodeFluent.Runtime.CodeFluentEntityState.Created;
        }
        
        [System.ComponentModel.BrowsableAttribute(false)]
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public virtual bool RaisePropertyChangedEvents
        {
            get
            {
                return this._raisePropertyChangedEvents;
            }
            set
            {
                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:

Object Explorer after creating the OrderProcess database

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;
 car.Save();
 ProductCollection products = ProductCollection.LoadAll();
 foreach (var p in products)
 {
  Console.WriteLine(p.Trace());
 }
 Console.WriteLine("\n\r\n\rPress Enter to exit.");
 Console.ReadLine();
}

You also have to add some configuration information to the console app’s configuration file. Within the <configuration> section add the following:

<configSections>
<section name="OrderProcess"
   type="CodeFluent.Runtime.CodeFluentConfigurationSectionHandler, CodeFluent.Runtime"/>
</configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
<OrderProcess connectionString="server=LOCALHOST;database=OrderProcess;Trusted_Connection=true" />
</configSections>

(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:

Command Prompt Window

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.

Evaluation of CodeFluent – Part 2

This is a continuation of SoftFluent’s CodeFluent Entities evaluation which I started in Part 1. Please see if before continuing here. Continuing with the CodeFluent Entities tutorial I’ll generate some code which can be used for different data store technologies. (This reminds me of Microsoft’s Entity Framework’s Code First way of generating storage entities.) CodeFluent Entities has 20 different providers that it can work with from the get go. The next step is to add a class library project to the OrderProcess solution. We’re going to name this new project OrderProcess. Remember in Part 1 we created a CodeFluent Entities project named OrderProcess.Model, so no conflict in project names. We delete the default class Class1 from the project. We add a folder named “Persistence Scripts” to this  project, which will have the SQL scripts that will generate the SQL Server scripts. In order to add this functionality we need to add a SQL Server Producer to the original OrderProcess.Model project. In there is a Producers folder, right clicking on it will bring up the Add New Producer dialog: Add New Producer According to the instructions for the tutorial we’re to open up the “Persistence Layer Producers” node. However, before doing that I did some poking around to see what else was available. Under the “Application Producers” node there’s things like Microsoft Office Lists, including lists from either MS Access of Excel. I also see “WPF CllickOnce Smart Client”, which apparently is in beta. This is of interest to me, as I’ve done some WPF development, and so I might come back later and see what that could lead to, but will have to save that for another time. There’s “Business Layer Producers”, which only has “Business Object Model”. The “Utility Producers” includes Entity Framework! It also has command line execution and Silverlight Object Model. And the last in the list on the dialog box is “Web Producers”, which has things in it like ASP.NET Web Controls and ASP.NET Web Service both labeled legacy. I would presume this means things like .asmx and possibly WCF. There are other things under “Web Producers”. It also includes SharePoint WebParts, which I imagine would be of interest to SharePoint developers. But in this case we’re working with the “Persistence Layer Producers”, which is for database types like MySQL, Oracle, PostgreSQL, SQL Server and SQL Server Azure. For this purpose I’m working with SQL Server, so I’ll select that. I then get this: Add New Producer SQL Server As you can see there’s a validation error here, but that’s because we’ve got to specify a folder to put the scripts generated. Here we choose that “Persistence Scripts” folder that we created in the new OrderProcess project. This pops up a Browse for Path or Project Folder dialog, which looks like this on my machine: Browse for Path of Project The next step wasn’t too obvious to me, but what you had to do was click on the empty textbox next to Connection String in the Add New Producer dialog. According to the tutorial instructions it says you’re to, “Click in the cell corresponding to the ‘Connection String’ value and type-in your connection string thanks to the ‘Connection String Editor’ window and click OK to validate the connection.” At this point I don’t know what my connection string is, as I don’t have a database out there to use. What I believe we’re to do is click on the button with the three dots in it that you see when you click on the textbox next to “Connection String”. Clicking on that you then get this: Connection String Editor My connection string looks different from what’s in the instructions, but that might be de to the version of SQL Server I’m using. (I’m using SQL Server 2014 Developer Edition.) I clicked on the Test Connection button, which is my habit. It couldn’t find the database, but it did suggest that it might be because the database doesn’t yet exist, which certainly is true. Or I could use the Master database, which I certainly do not want to do! Nevertheless, this s helpful. According to the instructions  CodeFluent Entities will create the database if it doesn’t exist, so I’ll click on the OK button instead. Clicking OK on the Add New Producer dialog adds the producer to the OrderProcess.Model project. My solution explorer now looks like this: Solution Explorer Next we’ll add a business object model producer. Going back to the Producers folder in the OrderProcess.Model project, we once again right click on the Producers folder, but this time we choose Business Layer Producers and under that Business Object Models. Once again you’ll see that the Target Directory has a validation error, but that’s only because we’re just adding this producer. In tis case we’ll select the OrderProcess folder and click OK. (I think it is important to point out here that “Business Object Model” doesn’t mean something related to Crystal Reports. I made that mistake, so don’t think that it has anything to do with Crystal Reports.) Here is how the Add New Producer dialog now looks on my machine: Add New Producer after adding BOM At this point we’re ready to build our solution, so I do a Control+Shift+B to build it. When I did I got the following error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)

I believe this is caused by the server name in the connection string dialog box being 127.0.0.1. I’m going to go into the connection string dialog box and change that to include (Local). I got to that by double clicking on the SQL Server producer so I could go to the connection string. This is how I changed it: Connection String Editor, with correction Now let’s try that build again. That fixed that problem. So if you encounter that error I got above, change your connection string to not use the IP address, but instead use local for your SQL Server. (Note: I am doing this with the local, default instance of SQL Server on my development box. Naturally if you’re using a named instance or a SQL Server instance remotely, then make appropriate adjustments.) Now that we’ve got the build to work, it generated a lot of the code to generate necessary SQL objects. The SQL scripts are written in the Persistence Scripts folder. I’ll continue this in part 3 of this evaluation.

Evaluation of CodeFluent – Part 1

(In the interest of full disclosure, I was contacted by SoftFluent, who kindly offered to furnish me with a enterprise version of their CodeFluent if I reviewed it here on my blog. What follows is my review.)

I’ve downloaded and installed SoftFluent’s CodeFluent. This is a suite that integrates into Visual Studio 2008 up to and include 2013. I’ve learned that CodeFluent also works with the new Visual Studio 2013 Community and Visual Studio 2015 preview. After downloading and installing CodeFluent you’ll see a new menu item in Visual Studio labeled “CodeFluent Entities”. CodeFluent creates a new project type that you can see when you do a File | New | Project. Select “CodeFluent Entities”. They include several example projects:

New Project

Something I think is important to remember is that, according to their instructions on getting started, the recommend that when creating a new project in VS using CodeFluent, that the name you specify include a “.Model” at the end of it, but the solution be named without the “.Model”. e.g.: If you’re going to call your solution MyApp, then you would choose a Name of “MyApp.Model” and a solution of “MyApp”.

After creating the new project you’ll have folders specific to CodeFluent, such as Surfaces, Parts, Stores and Model. In working through their Getting Started example there is a Default surface, and double clicking on it I get the following:

ribbon for working with the Default surface

At this point I ran into a problem while going through the tutorial, as it didn’t create the new entity on the surface. However I contacted their technical support and they were willing and helpful.

It is important to note that when adding entities, the first property you enter is taken to be the key for that property. Most likely you’ll choose something like ProductID or PersonID, depending upon what it is that you’re creating. Another thing to note at this point is that when you want to add properties, be sure to select the entity you’ve just created. I initially made the mistake of selecting the namespace (in the tutorial OrderProcess) instead of the new entity I’d created (Product). If you don’t select the newly created entity then the ribbon in the surface design will be wrong.

The data types offered here are interesting. You get the standard things like int, char, float, double and string, but they also have some interesting ones I didn’t expect like blob, image, audio and file. It would be fun to test those other sometime.

The next step in the tutorial was to create another entity, named Order. Here’s how things looked when I was finished creating the Order entity and saved the surface:

After creating the Order entity

In this case the tutorial had me create a property named Products, but define it as a string data type. This was to illustrate creating a many-to-many relationship between orders and products. I would have expected it to be a collection of some sort, but this is the way CodeFluent roles, at least as far as this tutorial goes.

In order to define a relationship between the Order and Product entities you use a Shift and drag with the mouse operation. I pressed the shift key and then clicked on the Products property of Order and dragged it to the Product entity header. This brought up the “Add a new relation” dialog box:

Add a new relationship

Please note that there is a discrepancy between the tutorial and what the adding new relationship dialog box actually has. I’ve put in here what the dalog box actually will look like after setting “<Unspecified>” to the Related property:

Add a new relationship 2

After pressing the OK button you’ll now have a diagram that looks like this:

Generated Relationship

(I will continue my review of CodeFluent in a future post coming soon.)

Tips for Querying Text Columns in SSMS

rodathome:

There’s some really handy tips here.

Originally posted on Learning SQL Server:

SQL Server Management Studio (SSMS) is a great tool for writing and running queries. This post will provide some extra tips on querying text fields in a database table. These include:

  • Query fields with long or formatted text
  • Copying strings by dragging them from the results grid
  • T-SQL query tips for working with strings

View original 500 more words

Just learned about Json.NET

I just learned about the incredibly useful Visual Studio add-in Json.NET (or JSON.NET, not sure which is the correct way to write it). I added it to a project I was working on recently, so that I could easily parse some JSON. It’s awesome!!! I recommend adding it via NuGet. Here’s a link to James Newton-King’s page, where he describes the excellent JSON.NET he wrote.

And here’s the link to the documentation for JSON.NET.