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 553 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.

An example of an ASP.NET app I wrote

I have been working for a number of years using various Microsoft technologies. One if ASP.NET, using what’s known as Web Forms. I decided, some years ago, to write a simple video management system, for our videos. If I were starting today, I might not write such an app, given such services like Ultraviolet, Flixster, VUDU, Netflix, etc., but still I like to have something to, well play around with and try out different ideas. So here’s the search page I wrote, for searching my database. This is the ASP.NET code:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Search.aspx.cs" Inherits="Search" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <h2>
    search media library</h2>
<p>
    <asp:SqlDataSource ID="sdsTypeOfShow" runat="server" 
        ConnectionString="<%$ ConnectionStrings:VideoLibraryConnectionString %>" 
        SelectCommand="SELECT * FROM TypeOfShow ORDER BY ShowName">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsImage" runat="server" 
        ConnectionString="<%$ ConnectionStrings:VideoLibraryConnectionString %>" 
        
        SelectCommand="SELECT DISTINCT ImageForShow FROM TypeOfShow WHERE (ShowCode = @ShowCode)" 
        onselected="sdsImage_Selected">
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlTypeOfShow" Name="ShowCode" 
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    Category to Search:
    <asp:DropDownList ID="ddlTypeOfShow" runat="server" 
        DataSourceID="sdsTypeOfShow" DataTextField="ShowName" 
        DataValueField="ShowCode" AutoPostBack="True" 
        onselectedindexchanged="ddlTypeOfShow_SelectedIndexChanged">
    </asp:DropDownList>
    <asp:Repeater ID="repImage" runat="server" DataSourceID="sdsImage">
        <ItemTemplate>
            <asp:Image ImageUrl='<%# Eval("ImageForShow", "~/Images/{0}") %>' runat="server" CssClass="RightJustify" />
        </ItemTemplate>
    </asp:Repeater>
</p>
<h3>
    (Enter at least one of the following)</h3>
<p>
    Episode name (a portion may be specified):
    <asp:TextBox ID="txtEpisodeName" runat="server" MaxLength="50" Width="394px"></asp:TextBox>
    <br />
    Synopsis (a portion may be specified):
    <asp:TextBox ID="txtSynopsis" runat="server" Width="425px"></asp:TextBox>
</p>
    <p>
        <asp:SqlDataSource ID="sdsEpisodes" runat="server" 
            CancelSelectOnNullParameter="False" 
            ConnectionString="<%$ ConnectionStrings:VideoLibraryConnectionString %>" 
            SelectCommand="spEpisodesByShowCodeAndName" SelectCommandType="StoredProcedure">
            <SelectParameters>
                <asp:ControlParameter ControlID="ddlTypeOfShow" DefaultValue="4" 
                    Name="ShowCode" PropertyName="SelectedValue" Type="Int16" />
                <asp:ControlParameter ControlID="txtEpisodeName" DefaultValue="" 
                    Name="EpisodeName" PropertyName="Text" Type="String" />
                <asp:ControlParameter ControlID="txtSynopsis" Name="Synopsis" 
                    PropertyName="Text" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:GridView ID="grdEpisodes" runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" BackColor="White" 
            BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
            DataKeyNames="ShowID" DataSourceID="sdsEpisodes" GridLines="Horizontal">
            <AlternatingRowStyle BackColor="#F7F7F7" />
            <Columns>
                <asp:HyperLinkField DataNavigateUrlFields="ShowCode,ShowID" 
                    DataNavigateUrlFormatString="~/Entries.aspx?ShowCode={0}&amp;ShowID={1}" 
                    HeaderText="Click to View" Text="View">
                <ItemStyle HorizontalAlign="Center" />
                </asp:HyperLinkField>
                <asp:BoundField DataField="EpisodeName" HeaderText="Episode" 
                    SortExpression="EpisodeName" />
                <asp:BoundField DataField="PlayTime" HeaderText="Play Time" 
                    SortExpression="PlayTime" />
                <asp:BoundField DataField="ShowCode" HeaderText="ShowCode" 
                    SortExpression="ShowCode" Visible="False" />
                <asp:BoundField DataField="Synopsis" HeaderText="Synopsis" 
                    SortExpression="Synopsis" />
                <asp:BoundField DataField="DateLastViewed" DataFormatString="{0:d}" 
                    HeaderText="Last Viewed" SortExpression="DateLastViewed" />
                <asp:BoundField DataField="ShowID" HeaderText="ShowID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="ShowID" Visible="False" />
                <asp:BoundField DataField="Rating" DataFormatString="{0:F3}" 
                    HeaderText="Our Rating" NullDisplayText="(Not yet rated)" 
                    SortExpression="Rating">
                <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
            </Columns>
            <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
            <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
            <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
            <SortedAscendingCellStyle BackColor="#F4F4FD" />
            <SortedAscendingHeaderStyle BackColor="#5A4C9D" />
            <SortedDescendingCellStyle BackColor="#D8D8F0" />
            <SortedDescendingHeaderStyle BackColor="#3E3277" />
        </asp:GridView>
        <br />
</p>
<p>
    <asp:Button ID="btnSearch" runat="server" CommandName="Search" Text="Search" 
        ToolTip="Perform search" />
    <asp:Button ID="btnReset" runat="server" CommandName="Reset" Text="Reset" />
</p>
</asp:Content>

The bulk of the work is all done in the ASP.NET code, but for completeness sake, here’s the C# code behind file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
            //
    }

        protected void ddlTypeOfShow_SelectedIndexChanged(object sender, EventArgs e)
        {
            //
        }

        protected void sdsImage_Selected(object sender, SqlDataSourceStatusEventArgs e)
        {
            //
        }
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }