Posts Tagged ‘VB.NET’

CodeFluent Entities: Build cross language and technology applications

April 4, 2012 Leave a comment

We’ve seen in the previous post (CodeFluent Entities Supports Multiple Database Systems) that once you invested the time into designing your application in CodeFluent Entities, you can switch from a database system to another by switching producers (e.g. Oracle Database to SQL Server, SQL Server to SQL Azure).

Well, the same logic also applies to upper tiers, for instance using the .NET Business Object Model Producer you can generate C# or VB.NET classes by selecting your desired target language:

Furthermore, the code generated by the .NET Business Object Model Producer supports all .NET Framework versions from 2.0 to 4.0 and runs on all .NET platforms: ASP.NET Web Forms, ASP.NET MVC, Windows Forms, WPF, Silverlight (2 to 4), SharePoint, Windows Workflow Foundation, WCF, etc.


In the end, CodeFluent Entities allows you to quickly build rock-solid foundations for your application whilst decoupling your business logic from the technology.



Carl Anderson

CodeFluent Entities is not an ORM

March 20, 2012 1 comment

CodeFluent Entities is a unique product integrated into Visual Studio 2008/2010/vNext which allows you to generate components such as scripts (e.g. T-SQL, PL/SQL), code (e.g. C#, VB), web services (e.g. WCF, ASMX) and UIs (e.g. ASP.NET, SharePoint, WPF).

The code generation process is model-first and continuous: from your declarative model, a meta-model will be inferred which code generators will then translate into code. Over 20 code generators (a.k.a. “producers”) are provided “out of the box” and can be combined to create your own application following your desired architecture, using your desired technologies.

For instance, adding an instance of the SQL Server Producer to your project will translate your model into a database (schemas, tables, stored procedures, views, constraints, etc.):

Adding an instance of the Business Object Model Producer will translate your model into .NET classes (C# or VB.NET) consuming the persistence layer:

Adding a WCF Producer will generate WCF services, contracts and proxies exposing your .NET classes:

Adding a WPF Smart Client Producer will generate a WPF application consuming the WCF services thanks to the generated proxy:

And that’s just an example of what you can do: you can also build ASP.NET web sites, SharePoint apps, Windows Forms apps, Silverlight apps, etc.

Your application is layered following best practices, all its business logic is in the middle-tier (the Business Object Model generated by the Business Object Model producer), and supporting a new technology gets down to adding a new producer or creating screens on the generated code.

Last but not least, you can create your own producer which translates this inferred meta-model into what you need.



Carl Anderson

March 19th 2012 Links: Windows 8, Visual Studio 11 Beta, Office 15, SQL Server, Tips

March 19, 2012 Leave a comment

Wow, this was a busy month!!

Here’s our latest batch in our link-listing series:

Windows 8

Windows 8 Consumer Preview

The Windows 8 Consumer Preview is now available!


Optimizing the .NET Framework Deployment Experience for Users and Developers

A great article which looks at the integrated experience that Windows 8 provides to run apps built for the .NET Framework.


Visual Studio 11 Beta

Welcome to the Beta of Visual Studio 11 and .NET Framework 4.5

Jason Zanders announces that Visual Studio 11 Beta, Team Foundation Server 11 Beta and .NET Framework 4.5 Beta are now available for download!


Introducing the New Developer Experience

In this blog post the Visual Studio Team introduces a few of the broad reaching experience improvements that they’ve delivered in Visual Studio 11.


Visual Studio 11 Beta Frequently Asked Questions (FAQ)

Jason Zanders answers some frequently asked questions on Visual Studio 11 Beta.

Note: Read the comments! Especially Patrcik Smacchia’s question:

-> Is there a chance that the VS team takes account of the thousands of negative feedbacks concerning greyish icons, and switch back to VSpre11 colorful icons?

To which Jason Zanders answered:

@Patrick – we have definitely heard the feedback.  as mentioned above, the beta is about getting feedback and will not reflect the final look and feel


Coming Soon: TFS Express

In TFS 11, Microsoft is introducing a new download of TFS, called Team Foundation Server Express which is free for individuals and teams of up to 5 users.


The C# 5.0 Beta Release is now available

Included in the Visual Studio 11 Beta, the C# version 5 and Visual Basic version 11 are shipped.


Office 15

Microsoft SharePoint 15: A 2012 release target, an app marketplace and more

Microsoft is adding new features to the next versions (Wave 15) of its SharePoint Server and SharePoint Online offerings. Mary Jo Foley takes an early look at some of them.


Microsoft chops Office 365 enterprise prices by 20%

Yay!! Price reductions!!


SQL Server

SQL Server 2012 RTM Available for Download

The new SQL Server version is available for download


Software Development

Envisioning the Future of UX: WebVisions NYC 2012

Some takeaways from the WebVisions NYC 2012 conference by Miao Wang



Carl Anderson

CodeFluent Entities and ASP.NET Web Forms: Validation

November 25, 2011 2 comments

In this post we’ll see how to implement validation in a form, data bound to a CodeFluent Entities generated class. We’re going to start from the page created in the Inserting Data post, and we’ll replace the DetailsView with a simple validation-enabled ASP.NET FormView.

Client Validation

First, we’ll start by adding ASP.NET field validators to avoid unnecessary server calls. Here’s the code:

<asp:ObjectDataSource runat="server" ID="ContactDataSource" TypeName="ContactAdmin.Contact"
    DataObjectTypeName="ContactAdmin.Contact" SelectMethod="LoadByEntityKey" InsertMethod="Insert">
        <asp:QueryStringParameter Name="key" QueryStringField="key" DefaultValue="-1" />
<asp:FormView runat="server" DefaultMode="Insert" OnItemInserted="OnContactInserted"
    DataKeyNames="Id, RowVersion" DataSourceID="ContactDataSource">
            <asp:Label runat="server" Text="First Name" /><br />
            <asp:TextBox ID="FirstNameBox" runat="server" AutoCompleteType="FirstName" Text='<%# Bind("FirstName") %>' />
            <asp:RequiredFieldValidator runat="server" Display="Dynamic" ErrorMessage="Field required."
                ControlToValidate="FirstNameBox" ValidationGroup="InsertContact" />
            <br />
            <br />
            <asp:Label runat="server" Text="Last Name" /><br />
            <asp:TextBox ID="LastNameBox" runat="server" AutoCompleteType="LastName" Text='<%# Bind("LastName") %>' />
            <asp:RequiredFieldValidator runat="server" Display="Dynamic" ErrorMessage="Field required."
                ControlToValidate="LastNameBox" ValidationGroup="InsertContact" />
        <asp:LinkButton ID="InsertButton" runat="server" Text="Create" CommandName="Insert"
            ValidationGroup="InsertContact" />
    <asp:Label ID="errorText" runat="server" ForeColor="Red" />

As you can see in the code sample above, we added two RequiredFieldValidator controls which ensure that each of our text boxes (FirstName and LastName) are filled when submitting the form. This way, if the form is incomplete, they’ll display the “Field required.” error message.

Here’s the result in action, if you click create with at least one empty field, no server call will be issued, and an error is shown to the user:



Server Validation

You can also set-up server-side validation. To do so in CodeFluent Entities, you can add one or several validation rules to your entity, on properties, or also extend the automatically generated Validate method with your own custom code using the OnBeforeValidate and/or OnAfterValidate licycle event rules.

As an example, we added a simple String Validation rule on the FirstName and LastName properties indicating that those properties cannot be null or empty, and cannot contain the ‘_’ character:


If you generate over your model, your Business Object Model will now enforce the following rule, and if ever you send a value with an invalid character to the server, it’ll now throw a CodeFluentValidationException. You’ll now need to handle it in your UI, and this is exactly what we’re doing by subscribing to the OnItemInserted event of the FormView. Here’s the event handler:

<script runat="server">    
    private void OnContactInserted(object sender, FormViewInsertedEventArgs e)
        if (e.Exception == null || e.Exception.InnerException == null)

        CodeFluent.Runtime.CodeFluentValidationException vex = e.Exception.InnerException as CodeFluent.Runtime.CodeFluentValidationException;
        if (vex == null)
            return; // Do nothing

        errorText.Text = vex.MessageWithoutCode;
        e.ExceptionHandled = true;
        e.KeepInInsertMode = true;

And here’s the result:


Note: the validation message can be localized and customized using messages in your model.

CodeFluent Entities and ASP.NET Web Forms: Master/Details

November 22, 2011 2 comments

In this post we’ll see how to set-up Master/Details pages declaratively using CodeFluent Entities-generated classes and database.

First, we’ll start by creating a page letting us display and edit a Contact instance. This one is pretty much like the “insert page” we created in our previous post:

<asp:ObjectDataSource runat="server" ID="ContactDataSource" 
        TypeName="ContactAdmin.Contact" DataObjectTypeName="ContactAdmin.Contact"
        SelectMethod="LoadByEntityKey" UpdateMethod="Save">
        <asp:QueryStringParameter Name="key" QueryStringField="key" DefaultValue="-1" />

<asp:DetailsView runat="server" DataSourceID="ContactDataSource" AutoGenerateRows="false"
        DefaultMode="Edit" DataKeyNames="Id, RowVersion">
        <asp:BoundField HeaderText="First Name" DataField="FirstName" />
        <asp:BoundField HeaderText="Last Name" DataField="LastName" />
        <asp:ButtonField CommandName="Update" Text="Save" ButtonType="Button" />

This page contains an object data source which if ever there’s an entity key specified in the url, it loads it from database, and the DetailsView control uses it as a data source. This page will be our details page.

Now our master page will simply list all Contact instances stored in database and allow end-users to view the details of one of them. Here’s how to do it:

<asp:ObjectDataSource runat="server" ID="ContactsDataSource" SelectMethod="LoadAll"
    TypeName="ContactAdmin.ContactCollection" DataObjectTypeName="ContactAdmin.Contact" />
<asp:GridView ID="GridView" runat="server" DataSourceID="ContactsDataSource" AutoGenerateColumns="False"
    DataKeyNames="EntityKey, RowVersion">
        <asp:HyperLinkField Text="Details" DataNavigateUrlFields="EntityKey" DataNavigateUrlFormatString="EditContact.aspx?key={0}" />
        <asp:BoundField HeaderText="Id" DataField="Id" />
        <asp:BoundField HeaderText="First Name" DataField="FirstName" />
        <asp:BoundField HeaderText="Last Name" DataField="LastName" />

The code is just like our first “Selecting Data” post, with the tiny difference that we added a HyperLinkField control which is configured to navigate to our details page created before, and using the current entity key so the details page will display the selected instance.





CodeFluent Entities and ASP.NET Web Forms Binding: Inserting Data

November 21, 2011 3 comments

In the previous posts we’ve seen how to display data declaratively using the generated code, so in this post we’ll illustrate how to insert data declaratively using ASP.NET Web Forms.

The first step is to configure your ObjectDataSource control to support inserts and updates, such as:

<asp:ObjectDataSource runat="server" ID="ContactDataSource" 
        TypeName="ContactAdmin.Contact" DataObjectTypeName="ContactAdmin.Contact"
        SelectMethod="LoadByEntityKey" InsertMethod="Insert">
        <asp:QueryStringParameter Name="key" QueryStringField="key" DefaultValue="-1" />

Note: We’re using the ‘LoadByEntityKey’ method as the select method instead of the ‘Load’ method to avoid a cast and support composite keys.

Now that we have a data source, we need to setup a control which will allow us to create or edit an instance of an entity. ASP.NET Web Forms provide several controls to do so including the DetailsView and FormView controls. In practice, they are almost the same, the main difference being that the DetailsView control uses a tabular layout where each field of the record is displayed as a row of its own where as the FormView uses a template which you can define yourself. For simplicity’s sake, we’ll use a DetailsView in this example which is defined as so:

<asp:DetailsView runat="server" DataSourceID="ContactDataSource" 
        DefaultMode="Edit" DataKeyNames="Id, RowVersion">
        <asp:BoundField HeaderText="First Name" DataField="FirstName" />
        <asp:BoundField HeaderText="Last Name" DataField="LastName" />
        <asp:ButtonField CommandName="Insert" Text="Insert" ButtonType="Button" />

Note: You must set the DataKeyNames property for the automatic updating, deleting, and inserting features of the DetailsView and FormView controls to work.

And here it is you now have an insert form to create a new contact:


CodeFluent Entities and ASP.NET Web Forms Binding: Selecting Data

November 16, 2011 3 comments

CodeFluent Entities, using the Business Object Model producer, generates a set of .NET classes (C# or VB.NET) which you can easily use in any .NET application including ASP.NET Web Forms one.

Today’s post is the first of a series I’ll do over the next week that will illustrate how to do common operations creating a hand-made ASP.NET Web Form web site using a CodeFluent Entities generated Business Object Model.

So let’s start with the basics and how to select data. The key control to do that is the ObjectDataSource. In this example, we’re using it to load all contacts of my application:

<asp:ObjectDataSource runat="server" ID="ContactDataSource" SelectMethod="LoadAll" TypeName="ContactAdmin.ContactCollection" DataObjectTypeName="ContactAdmin.Contact" />

As you can see we’re mapping the ObjectDataSource control on the LoadAll method of the ContactCollection class, and indicating that the manipulated data objects are of the Contact type, which is my entity class. Please note that all this was automatically generated from my model, which contains a single entity named Contact.

To display the returned data, let’s use an <asp:gridview> control.  The Gridview below has 3 columns, all of them being standard BoundFields:

<asp:GridView ID="GridView" runat="server" DataSourceID="ContactDataSource" AutoGenerateColumns="False">
        <asp:BoundField HeaderText="Id" DataField="Id" />
        <asp:BoundField HeaderText="First Name" DataField="FirstName" />
        <asp:BoundField HeaderText="Last Name" DataField="LastName" />

As you can see the GridView control uses the ContactDataSource as a data source, and displays the Id, FirstName and LastName properties of my Contact class. Here’s the result:


CodeFluent Entities: The Business Object Model

November 10, 2011 Leave a comment

The Business Object Model (a.k.a. BOM) is generated by the Business Object Model Producer and is a .NET translation of your platform independent model which you designed in CodeFluent Entities.

In practice it’s a set of C# or VB.NET classes which was inferred from your entities. Two classes are generated per entity, one representing the entity (e.g. Customer) and one representing a collection of this entity (e.g. CustomerCollection). This set of classes is built to contain all the business logic of your application (entities, methods, rules, custom code, etc.) and to be easily used in upper layers.

By that I mean that this BOM can be used across all .NET applications may they be WPF, Windows Forms, ASP.NET Web Forms, ASP.NET MVC, WCF web services, ASMX web services, console applications, Windows Workflows and so on.

Furthermore, those classes are built to ease your life when building your app:

  • They are all serializable (XML, .NET binary / SOAP, WCF, etc.)
  • They are all partial
  • They do not derive from a base technical class but are plain old classes
  • They implement by default an extensive set of .NET inferfaces to ease your life (System.ComponentModel.IDataErrorInfo, System.IEquatable<T>, System.ComponentModel.INotifyPropertyChanged, System.ICloneable, System.IComparable<T>, etc.)

On a higher level, the BOM also provides application oriented features that are common to enterprise-class applications so developers won’t have to code them over and over again from one project to another. Here’s a bulk list of out-of-the-box features provided by the BOM:

  • Data Binding,
  • Data Validation,
  • Paging and Sorting,
  • Security,
  • Localization (with .NET resources, but also data localization),
  • Concurrency,
  • Transactions,
  • Caching,
  • Blob management.

I’m probably be missing some, but you get the general idea: let the tool take care of all the plumbing and recurrent but yet necessary code so you can spend time on what matters such as the UI.

Furthermore, since those features are implemented in the BOM, they’ll be shared by all clients using that BOM so that UI is just UI, meaning that if you started by developing a Windows Forms application and then need to go to WPF, you don’t have to write everything over, but just the UI specific code. And this is also true from desktop to web, web to mobile or even in-house to cloud.

To paraphrase Rockford Lhotka in his "Silverlight 6 doesn’t matter" post, in the end the key is architecture.


Get every new post delivered to your Inbox.

Join 49 other followers