Archive

Archive for December, 2011

Adding your own models to the CodeFluent Entities Starter Wizard

December 29, 2011 Leave a comment

As mentioned in the posts “The Starter Wizard” and “New CodeFluent Entities Milestone”, the Modeler provides a wizard creating the structure of your solution as well as configuring your producers so they point to the freshly created projects.

Among the wizard pages, there’s a page allowing you to select a model template from which you want to start:

Models displayed in this page are the default official ones (blank, and sample ones), but just as you can add your custom producers or custom rules to the Modeler, you can add your custom models to his screen as well.

First you need to locate the custom configuration. You’ll find this information by:

  • opening Visual Studio,
  • go to “Tools > Options… > CodeFluent Entities”,
  • and select the advanced view using the advanced button at the top of the property grid.

As you’ll see, there’s a property named “Custom Configuration File Path” which points to a Custom.config file:

Open this file (or create it if necessary) and add the following XML content to it:

<codeFluent.Modeler>
  <starterWizardModelDescriptors>
    <starterWizardModelDescriptor name="Test" fileName="Test.cfxproj" description=”A custom model.” />
  </starterWizardModelDescriptors>  
</codeFluent.Modeler>

This indicates the Starter Wizard to display a model named “Test”, corresponding to the “Test.cfxproj” project, in the “Select your model” wizard page.

Note: the cfxproj file should be placed in CodeFluent Entities’ Visual Studio templates folder which is “C:\Program Files (x86)\SoftFluent\CodeFluent\VSTemplates\Projects”).

Save the file, open your wizard, here’s what you should see now:

And voilà: our custom model project is now proposed in the wizard!

Carl

CodeFluent Entities: Using the SQL Server Template Producer to generate a script

December 26, 2011 3 comments

In this post we’ll see how using CodeFluent Entities’ SQL Server Template Producer, you can generate SQL scripts using  the built-in template engine whilst accessing the inferred meta-model, and then automatically deploy the generated script on your desired server.

In this particular scenario, a customer wanted to be able to version his generated stored procedures so his DBA could easily spot those that are of an other version. There are no built-in feature to do this natively using CodeFluent Entities, however versioning your stored procedures can be done with a few lines of code using the SQL Server Template Producer.

First we’ll write a script adding an extended property named “ModelVersion” on a generated stored procedure:

BEGIN TRY
    exec sp_addextendedproperty
        @name = N’ModelVersion’,
        @value = ‘<Version>’,
        @level0type = N’Schema’, @level0name = ‘dbo’,
        @level1type = N’Procedure’,  @level1name = ‘Test_Load’;
END TRY
BEGIN CATCH
    exec sp_dropextendedproperty
        @name = N’ModelVersion’,
        @level0type = N’Schema’, @level0name = ‘dbo’,
        @level1type = N’Procedure’,  @level1name = ‘Test_Load’;
    exec sp_addextendedproperty
        @name = N’ModelVersion’,
        @value = ‘<Version>’,
        @level0type = N’Schema’, @level0name = ‘dbo’,
        @level1type = N’Procedure’,  @level1name = ‘Test_Load’;
END CATCH
GO

Note: I apologize to all DBAs out there, this script is just a quick and dirty way to create extended properties and overwrite the existing one if ever it already exists.

Now that we have our working script we’re going to turn it into a template which the SQL Server Template Producer will run:

[%@ namespace name="CodeFluent.Model"%]
[%@ namespace name="CodeFluent.Model.Persistence"%]
/* [%=Producer.GetSignature()%] */
[% foreach (Procedure procedure in Producer.Project.Database.Procedures) { %]
BEGIN TRY
    exec sp_addextendedproperty
        @name = N’ModelVersion’,
        @value = ‘[%=Producer.Project.ModelCheckSum%]‘,
        @level0type = N’Schema’, @level0name = ‘dbo’,
        @level1type = N’Procedure’,  @level1name = ‘[%=procedure.Name%]‘;
END TRY
BEGIN CATCH
    exec sp_dropextendedproperty
        @name = N’ModelVersion’,
        @level0type = N’Schema’, @level0name = ‘dbo’,
        @level1type = N’Procedure’,  @level1name = ‘[%=procedure.Name%]‘;
    exec sp_addextendedproperty
        @name = N’ModelVersion’,
        @value = ‘[%=Producer.Project.ModelCheckSum%]‘,
        @level0type = N’Schema’, @level0name = ‘dbo’,
        @level1type = N’Procedure’,  @level1name = ‘[%=procedure.Name%]‘;
END CATCH
GO
[% } %]

As you can see this template iterates throughout all procedures of the virtual database inferred from my model, and adds a ModelVersion extended property.

Now in your CodeFluent Entities project, add an instance of the SQL Server Template Producer with your template directory as the “Source Directory” and build over your model. The SQL Server Template Producer will generate a script file from your template, and run the script on the server. Using SQL Server Management Studio we’ll now see our extended properties on all our generated stored procedures:

image

 

Carl

Visual Studio Tip: Opening XAML files fast

December 22, 2011 2 comments

Developing WPF screens in Visual Studio 2010 SP1 using the Windows Presentation Foundation Designer, even in code view, can still be a drag as it’s slow and especially when opening a file.

Always open documents in full XAML view

The first step is to not open the design view. To do so go in “Tools > Options > Text Editor > XAML > Miscellaneous”, and check the “Always open documents in full XAML view” option:

image

Using the Source Code Editor

Openening XAML files in the Code View is better but if that’s still not enough for you as it was for me, here’s the ultimate tip: instead of opening them using the default editor (Windows Presentation Foundation Designer), open them using the “Source Code (Text) Editor“: it’s as fast as opening a classic XML file, and you’ll still get the auto-completion, which is not the case when using the “XML (Text) Editor” (yeah, I tried that one first Winking smile).

To set that up, right-click on a XAML file and select “Open With…”, then in the dialog set the “Source Code (Text) Editor” as the default editor by clicking on the “Set as Default” button:

image

Now try opening one of your big WPF screen, and taa-daa!! It’s lightning fast!

Carl

CodeFluent Entities: Blobs and the HttpResponse.ContentType

December 22, 2011 Leave a comment

To serve blobs on the web, CodeFluent Entities generates a HttpHandler which loads and returns a blob from a given URL. A cool feature of this HttpHandler is that it sets the HttpResponse.ContentType property to the HTTP MIME type corresponding to the returned stream, so the end-user’s browser will use the appropriate piece of software to read it. For instance, returning a MP3 file will launch the corresponding default program such as Windows Media Player, Acrobat Reader if it’s a PDF, or Microsoft Word if it’s a DOCX.

The HttpHandler knows two ways to retrieve the MIME type:

  • Using the IIS Metabase (default)
  • Using the Registry

Using Web MIME Types (default)

CodeFluent Entities is a 6 year old product and at the time this feature was developed Internet Information Services (IIS) was in version 6.0. With IIS 7 and IIS 7.5 the metabase is not installed by default so to get MIME types from IIS you need to have the IIS Metabase and IIS 6 configuration compatibility option enabled (cf. screenshot underneath).

image

Furthermore, the account used to access the metabase needs to be allowed to do so which might not be the case do so. That’s exactly what happened if you got this error:

CodeFluent.Runtime.CodeFluentRuntimeException was unhandled by user code

Message=CF1033: An error has occured trying to read metabase path ‘IIS://localhost/MimeMap’. Current user is ‘NT AUTHORITY\IUSR’.

Source=CodeFluent.Runtime

Code=1033

MessageWithoutCode=An error has occured trying to read metabase path ‘IIS://localhost/MimeMap’. Current user is ‘NT AUTHORITY\IUSR’.

Microsoft provides a tool named MetaAcl which you can use to modify the default permissions that are set on an Internet Information Services (IIS) metabase. So let’s say my web site is ran using the Local Service identity; using the following command line grants the read permission to the Local Service user account to access my IIS metabase:

Metaacl.vbs IIS://localhost/MimeMap “NT AUTHORITY\LOCAL SERVICE” R

Using Registry MIME Types

To use registry MIME types all you need is to set the useWebMimeTypes to false it will switch to registry mode. Here a sample configuration (replace the section name ‘Sample’ by your default namespace):

<configuration>
  <configSections>
    <section name="Sample" type="CodeFluent.Runtime.CodeFluentConfigurationSectionHandler, CodeFluent.Runtime" />
  </configSections>
  <Sample useWebMimeTypes="false" connectionString="server=(localhost);database=Sample;Trusted_Connection=true" />

Carl

CodeFluent Entities: Customizing the Method Body

December 19, 2011 Leave a comment

CodeFluent Entities provides “Methods” which allows developers to define custom data accessing methods (load, loadone, delete, count, search) which persistence producers will translate into stored procedures.

For instance, the following method:

image

Will generate the following stored procedure:

CREATE PROCEDURE [dbo].[Setting_LoadByName]
(
@Name [nvarchar] (256)
)
AS
SET NOCOUNT ON
SELECT DISTINCT [Setting].[Setting_Id], [Setting].[Setting_Name], [Setting].[Setting_Value] FROM [Setting]
    WHERE ([Setting].[Setting_Name] = @Name)

RETURN

You can also create what we call Raw methods which are platform specific code such as T-SQL or PL-SQL, but you can also mix both, that is to say create a CFQL method so upper layers benefit from the out-of-the-box features provided by such methods and just override the actual body of the stored procedure.

For instance say you wanted to create a topped method which the number of returned rows can be passed to the method. The “TOP” statement doesn’t exist in CFQL (see TOP in CFQL for more information) so a way to do this would be to mix CFQL and T-SQL for instance.

To do so, start by defining your CFQL body:

image

And then define the Raw Text property of the body (select your method, and click on the “Bodies” property in the property grid):

image

Once this is done, if you build your model, the stored procedure quoted hereunder will be generated, and in upper layers your method will look just as expected (returning a SettingCollection, mapping returned columns to properties, and taking an int maxCount parameter):

CREATE PROCEDURE [dbo].[Setting_BoundedLoadAll]
(
@maxCount [int]
)
AS
SET NOCOUNT ON
SELECT TOP(@maxCount) * from Setting
RETURN

CodeFluent Entities Webcast – December 6th 2011: Follow-up

December 16, 2011 Leave a comment

Following the CodeFluent Entities Webcast post, an increasing number of you asked for the PowerPoint presentation used in the webinar: so here it is!

Webinar Presentation (12/06/2011)

CodeFluent Entities Importer: Deducing Relationships

December 14, 2011 Leave a comment

Last week we hosted a live webcast – which by the way was recorded and is available here – and following it we had several questions regarding the demo where we created a model from the Northwind database, and especially on how the tool deduced the relationships between entities.

The CodeFluent Entities importer detects foreign keys and transforms them into model relations, so we’re sorry to disappoint so many of you but there is absolutely no magic here!

The importer in fact relies on a database abstraction layer that presents a common interface for all supported databases or modeling systems that can be imported.

Here is a screenshot demonstrating how this intermediary abstraction layer « sees » an « old » Northwind Access Database, prior being imported, in a tool we call « Model and Database Explorer ».

image

Here you see two foreign keys that will be transformed into relations between entities if this database is imported as a model.

Now, back to magic! Even if there are no foreign keys on tables, the importer is truly capable of casting some voodoo spells Smile

There is a parameter to the importer which is highlighted here:

clip_image002

When this parameter is set to true (the default value), the importer will try to determine automatically relations using column names. For example, say you have two tables like these:

Customer

  + CustomerId

  + Name

Order

  + OrderId

  + Reference

  + CustomerId

If no foreign key is declared, the importer will « guess » if this is a 1:M or 0:M relation.

MDDAY 2011: CodeFluent Entities & AlloCiné

December 9, 2011 Leave a comment

End of November, we did a joined CodeFluent Entities presentation at the French MDDAY event – MDDAY standing for Model Driven Day – where AlloCiné, a major French web entertainment player, started by sharing their experience using CodeFluent Entities and we then demoed the product.

You’ll find more information on that presentation on our company blog: http://blog.softfluent.com/

CodeFluent Entities Webcast – December 6th 2011

December 9, 2011 2 comments

In this webinar a product team member demonstrates CodeFluent Entities.

Watching this webcast you’ll see:

  • How to generate entire .NET applications from scratch
  • How to absorb functional changes smoothly thanks to continuous generation
  • How to decouple your business logic from technology
  • How to import an existing database

Technologies featured in this product demonstration are:

  • CodeFluent Entities,
  • Visual Studio 2010,
  • Microsoft SQL Server,
  • .NET (C#),
  • .NET Console Application,
  • Windows Communication Foundation (WCF),
  • Windows Presentation Foundation (WPF),
  • ASP.NET MVC,
  • Microsoft Access

Here’s a recording of the full webcast:

CodeFluent Entities Webcast (2011-12-06)

Note: Watch the video in HD by selecting the 720p option instead of the default 360p on the bottom right section of the player.

CodeFluent Entities & WPF

December 6, 2011 Leave a comment

Last week we posted a series of blog posts on “CodeFluent Entities & WPF”, so here’s a quick post listing all those posts:

There are less posts than in the ASP.NET series, mostly because writing desktop applications has less restrictions and developers can call the generated methods directly. Feel free to comment this post if you’re interested in a post illustrating a particular feature.

Hope this helps,

Carl

Follow

Get every new post delivered to your Inbox.

Join 48 other followers