The official Fatica Labs Blog! RSS 2.0
# Thursday, 17 November 2011

Even if Linq To NHibernate provider allow us to write query in a strongly type manner, it is sometimes needed to works with property names literally. For example in a RIA application a service can receive a column as a string containing the name of the property to order by. Since Linq to NHibernate is a standard Linq provider, we can leverage a standard dynamic linq parser. This is achieved by using an old code by MS, known as System.Linq.Dynamic. By following the link you will find a download location that point to an almost just a sample project that eventually contains the file Dynamic.cs that contains some extension method allowing to merge literal parts in a type safe linq query.

Let’see an example:

var elist = session.Query<MyEntity>()
              .OrderBy(“Name descending”)
              .Skip(first)
              .Take(count)
              .ToList();

I supposed we have a property called Name on the class MyEntity. The OrderBy taking a string as a parameter is an extension method provided by Dynamic.cs, and in order to have it working you just need to merge the file dynamic.cs in your project and import System.Linq.Dynamic. Of course you will have extension for Where and for other linq operators too.

Thursday, 17 November 2011 13:15:19 (GMT Standard Time, UTC+00:00)  #    Comments [5] - Trackback
CodeProject | NHibernate

# Thursday, 03 November 2011

As we know the Caliburn Micro library implements a screen conductor to handle multiple screen models with only one active, typically used for tabbed views, that is easy to implement by deriving your model from Conductor<IScreen>.Collection.OneActive. This works out of the box with the standard tab control, but it is not possible to use it for example with the tabbed documents in AvalonDock. The only solution I found, that for some reason I will say below, is this one. I don’t like this solution because it force to write code inside the view, that is not acceptable in a pure MVVM solution, so I preferred to insulate the code in an attached behavior. In addition the presented solution will works correctly with the Activate/Deactivate/CanClose strategy on each document. We just need to modify the view markup as in the example below:

As you can see we just added an attached property UseConductor.DocumentConductor that we bind to the current model. Of course the model is a OneActive screen conductor. The behavior take care to connect the document items of the DocumentPane with the screen conductor items. If each screen implements IScreen, the proper Activate/Deactivate/CanClose are called, so we can even handle the case of canceling the close of a dirty document. Here the attached behavior code: An example MainModel can be the following one:

( we just add some random document to see how it behave )

And here below an example of a single screen  model:

So we have the conductor, without touching the view code, and without creating a custom screen conductor.

Thursday, 03 November 2011 19:52:59 (GMT Standard Time, UTC+00:00)  #    Comments [6] - Trackback
Caliburn | WPF | CodeProject

# Wednesday, 02 November 2011

Sometimes when we use mapping by code we want to see the generated HBM, just to understand if all is working as expected. I did this in some my old posts by dumping the hbm with an helper method, but I simply miss that the function exists as an extension method. Here below an example:

 var compiled = mapper.CompileMappingForAllExplicitlyAddedEntities();
#if DEBUG
            Trace.WriteLine(compiled.AsString());
#endif
            cfg.AddMapping(compiled);

 

We simply need to include the following using:

using NHibernate.Mapping.ByCode;

Here I use the AsString method that serialize in a string the compiled mapping.
Wednesday, 02 November 2011 14:39:29 (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
NH Mapping By Code | NHibernate

# Tuesday, 01 November 2011

In order to start with Azure we need to prepare our Visual Studio with the azure SDK. Even if the Windows Azure tools for Microsoft Visual Studio is only supported by Visual Studio 2010 & Visual Studio 2010 SP1 editions, you can download a standalone SDK providing low level tools, the API ( ie the client dll ) the documentation and the samples we need for start.

So the first step is downloading the Windows Azure SDK and install it. After the installation is complete you will see this in your Server Explorer:

image

So the new computer and barrels painted in azure means that we have the emulators for the compute service and storage locally running, this mean we can start to try something without buy a real account in the cloud with jus few differences. First time you expand the Storage a backend for it is created under SQL Express, but you can use another SQL server instance by following these instructions.

Another gift from Visual Studio Tools are the new application templates:

image

This is enough to get the environment ready on.

Tuesday, 01 November 2011 08:34:48 (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
azure | cloud

# Tuesday, 25 October 2011

I’m starting to learn something about cloud computing, probably with Azure: just because I’m a little .NET biased Smile 

image

What I like in the Cloud approach is the hardware availability – scalability. As a drawback we need even more broad band reliable collection, thinking on something like this, because the whole strategy fails if the end connection, the one with the user, fails or it is poor.

Now what we need is just a rocking idea to start…

Tuesday, 25 October 2011 14:24:18 (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
communication | technology

# Thursday, 20 October 2011

Since it is boring having to specify every time the Schema a table belongs to, it would be nice having a conventional strategy to automatically wire up this information. With NHibernate mapping by code functionality this is simple. The strategy I propose is having the last part of the entity namespace being equal with the schema. So for example we have an entity Product in the schema named Production we define the entity as:

MyEntities.Production.Product

Then by using a ConventionModelMapper we can write:

public class MyModelMapper:ConventionModelMapper
    {
        public MyModelMapper()
        {
            this.BeforeMapClass += (modelInspector, type, customizer) =>
                {
                    customizer.Schema(type.Namespace.Split('.').Last());
                };
        }
        
    }

And we achieve to write less line again :)

Thursday, 20 October 2011 12:05:18 (GMT Daylight Time, UTC+01:00)  #    Comments [1] - Trackback
NH Mapping By Code | NHibernate

My Stack Overflow
Contacts

Send mail to the author(s) E-mail

Tags
profile for Felice Pollano at Stack Overflow, Q&A for professional and enthusiast programmers
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2019
Felice Pollano
Sign In
Statistics
Total Posts: 157
This Year: 0
This Month: 0
This Week: 0
Comments: 127
This blog visits
All Content © 2019, Felice Pollano
DasBlog theme 'Business' created by Christoph De Baene (delarou) and modified by Felice Pollano
Nike Winkels Nederland Outlet Nike Nederland Store Outlet Nike Nederland 2015 Outlet Nike Outlet Online Nike Sneakers Outlet