Tuesday, December 20, 2011

[Publication] White Paper in collaboration with Microsoft:
Second Chapter on How to develop applications for the Cloud

I am happy to announce that you can find the second chapter of a whitepaper on how to develop applications for the Cloud using the Windows  Azure platform written by me, François Merand and Laurent Gautier on the official Visual Studio homepage.

http://www.microsoft.com/france/visual-studio/scenarios/developper-pour-le-cloud.aspx

image

We will continue publishing the other chapters in the next weeks so stay tuned as we progress on implementing our example BDTheque application and finalizing our Whitepaper.

You can find the source code of the BDTheque application here.


Share/Save/Bookmark

Friday, December 2, 2011

[Publication] White Paper in collaboration with Microsoft:
First Chapter on How to develop applications for the Cloud

I am happy to announce that you can find the first chapter of a whitepaper on how to develop applications for the Cloud using the Windows  Azure platform written by me, François Merand and Laurent Gautier on the official Visual Studio homepage.

http://www.microsoft.com/france/visual-studio/scenarios/developper-pour-le-cloud.aspx

image

We will continue publishing the other chapters in the next weeks so stay tuned as we progress on implementing our example BDTheque application and finalizing our Whitepaper.

You can find the source code of the BDTheque application here.


Share/Save/Bookmark

[Publication] Interview with Developpez.com and Microsoft concerning SQL Azure and its newest features

Just a quick note that you can find an article in French written by Gordon Fowler concerning my interview with Microsoft and Developpez.com on the maturity of SQL Azure, its advantages and its new features (SQL Azure Reporting, SQL Azure Data Sync, SQL Azure Federation) under the following address.

http://www.developpez.com/actu/39580/-SQL-Azure-devient-l-egal-de-SQL-Server-Microsoft-et-Sogeti-reviennent-sur-les-nouveautes-de-la-base-de-donnees-hebergee/

image


Share/Save/Bookmark

Thursday, December 1, 2011

[Publication] Article in French Programmez Magazine on Design By Contract and Code Contracts using C# 4.0

You can find an article of 4 pages concerning Design By Contract and more specific Code Contracts using C# 4.0 in the French Programmez magazine No.147 written by me and Fathi Bellahcene.

image

First Page and Second Page (low resolution)

Third Page and Fourth Page (low resolution)

The article is written in French but as always I will write some English articles on my Blog in the next weeks. So stay tuned if you are interested in getting to know Code Contracts in C# 4.0 and how it may help you to improve the quality of your code .

You can find the source code here:
http://designbycontract.codeplex.com


Share/Save/Bookmark

Thursday, November 3, 2011

[Certifications] Now TOGAF9 certified !

Just to let you know that I passed the two TOGAF9 exams lately (Foundation & Certified) during the combined OG0-093 exam.

I am happy to announce that I am now TOGAF9 certified !

Cert_ITSpec

For more information concerning the TOGAF9 Framework please consult the official website of The Open Group : http://www.opengroup.org/togaf/.


Share/Save/Bookmark

Wednesday, October 19, 2011

[C# and Language] Compiler as a Service (CaaS)
Roslyn CTP released

Microsoft announces the release of its Roslyn CTP, the first example of the implementation of CaaS (Compiler as a Service) that I presented some time ago. This release marks a significant step to how Microsoft thinks of compilers. The C# and VB compilers are no longer black boxes.  All that rich information about code is now exposed as an object model that can be easily consumed. In addition, Microsoft has released a preview of the first-ever Interactive window for C# that contains full IDE support, including IntelliSense and even automatically detecting missing using directives.

You can download it here:
http://msdn.com/roslyn

image


Share/Save/Bookmark

Monday, October 17, 2011

[Tutorial] Code First with Entity Framework 4.1
Part5: Concurrency Management & Conclusion

Assuring the consistence and coherence of data in the database is a very important topic. Concurrency problems come up when multiple source (clients, systems, etc…) try to modify data at the same time.Your application must be able to choose whether to accept or reject any data changes that arrive simultaneously.

Simultaneous execution of transactions must provide the same results as sequential execution of those same transactions.If you achieve this goal then your system is well prepared for correct concurrency handling.

Entity Framework 4.1 includes a very complete concurrency approach. The DbContext class that we already saw before allows for efficient concurrency handling.

First Wins

This resolution strategy defines that the first modification wins if there are concurrency conflicts. All following modifications on the same data are ignored and clients get exceptions that tell them that their transactions did not complete because the data was already changed.

You have to determine which properties might be subject to concurrency problems. You may have properties which do not need any concurrency handling. A property that contains the last modified date might not need to implement any concurrency handling for example.

All properties that must be checked for concurrency need to have the [ConcurrencyCheck] attribute set as shown below:

image

If you don't like using attributes, you may also use the CodeFirst Fluent API on your properties to activate concurrency checking:


image

You have to add concurrency checks only on properties that really need it since this will have some impact on performance within your code. The more properties with activated concurrency checks you have the worse your performance might be depending on your implementation !

image

In the example above we retrieve a manager object from the database, store it in memory and change some property values (but only in memory). We then change some values on the same data directly in the database to simulate concurrency as if two clients did modifications at the same time.

When we call the SaveChanges() method you will see that we get an exception of type DbUpdateConcurrencyException. This is where you need to add your custom concurrency conflict resolution logic. In this example we decided to guard the first modification (First Wins). In the last step we update the context in memory with the data that was changed in the database via ex.GetEntry(context).Reload().

Last Wins

This is the default resolution strategy of EF 4.1 in case of concurrency conflicts. It defines that the last modification wins if there are concurrency conflicts. All previous modifications on the same data are overwritten. Clients only get informed if they use the [ConcurrencyCheck] attribute, some kind of log, some event or other treatment.

image

The example above shows how to implement a Last Wins approach. If there are exceptions due to concurrency conflicts we store the new initial value in the context thus synchronizing with the source. We then retry saving the data until it is saved to the database and the processing is successfully completed.

Conclusion

I hope this tutorial gave you a first insight on the new features of EF 4.1 which are quite powerful even for code purists. With the new features presented in this tutorial EF becomes one of the most complete products on the ORM market. Today, it is the only product that proposes all 3 approaches
CodeFirst, Database First and Model First at the same time.

Some features are missing like auto-synchronization of the database if the class structure changes and stored procedure integration but they will be added in the next weeks / months.

Share/Save/Bookmark

[.NET 4.5] In-Place Upgrade to .NET 4.0 SP1

After the BUILD conference we now have more information on how Microsoft plans to do the upgrade from .NET 4.0 SP1 to .NET 4.5 and what this upgrade will imply.

Contrary to all other upgrades in the last years this will not be a side-by side upgrade but instead an in-place update. The .NET 4.0 SP1 framework will be replaced on the system during the upgrade process. Furthermore it seems that you won’t be able to go back once you have done the upgrade.

To allow such an update Microsoft will have to assure that old code that ran under .NET 4.0 SP1 will still run correctly under .NET 4.5 which is not an easy task. But the Microsoft staff is currently working hard to assure everything will work seamlessly when the final version of .NET 4.5 is shipping.

I will post a migration tutorial when the final version will be published and try to help you in having a good migration strategy.


Share/Save/Bookmark

Wednesday, September 14, 2011

[MS Days 2011] ATE during Microsoft Days in Paris

I will be acting as ATE (Ask The Expert) during the Microsoft Days in Paris the 4th of October and will be happy to respond to any questions you might have concerning Microsoft products during the breaks in between the different sessions.

You will find me at one of the stands wearing a special shirt (!)and being happy to exchange with you on any technical subject you might have. See you there the 4th of October !!

Please mind that the Microsoft Days will be present in different cities all around France so choose which is the nearest to you and try to find some time to assist. It is well worth getting to know the latest technologies and news on upcoming Microsoft products. And the best of all : It is for free !

Following are all the dates and places of the Microsoft Days end of 2011:

  • 27 September : Nantes
  •  04 October : Paris
  • 13 October : Strasbourg
  • 20 October : Lille
  • 03 November : Marseille
  • 09 November : Lyon
  • 15 November Bordeaux

The event is free of charge and you can register here:

image


Share/Save/Bookmark

Monday, August 1, 2011

[Tutorial] Code First with Entity Framework 4.1
Part4: Data Audit

All properties within objects managed by the Entity Framework can be audited. This is very helpful if you need to display changes to objects before saving them, cancel modifications by resetting the current value with the initial value or handling concurrency problems.

Entity Framework 4.1 permits accessing the following property versions of an entity:

  • Database Value
  • Original Value
  • Current Value

image

When executing the code above the different values for the Name property of the Manager class are displayed.

image

As you see, adding audit functionality to your applications is really quick to do, Entity Framework 4.1 contains already everything necessary to implement it very easily.


Share/Save/Bookmark

Wednesday, July 27, 2011

[Tutorial] Code First with Entity Framework 4.1
Part3: Data Validation

Data validation is a very important subject when developing applications. You have to assure good quality and high integrity of your data for being able to exploit it correctly. You need to avoid storing any corrupt, incomplete or wrong data in your database which will most certainly lead to misbehavior within your applications.

The following example shows how to implement a constraint on the Name property (required / string length between 5 and 20 characters) via Data Annotations.

image

Validation is automatically done when calling the Save method to persist any changes applied to your objects in memory. But you may as well do it before by calling the GetValidationErrors method.

image

Lets say when the code above is executed it will fail due to validation errors. In this case error messages will be displayed for each constraint that was not respected. In our example we defined that the Name property should have a minimum string length of 5 characters, but the property only contains 4 characters. Since we did not define a specific error message, a generic error message will be displayed for this validation error.

image 

There are multiple Data Annotations that allow for type validation, format validation, regular expression matching, etc….


Share/Save/Bookmark

Tuesday, July 26, 2011

[Tutorial] Code First with Entity Framework 4.1
Part2: Data Annotations & Code First Fluent API

The new version of Entity Framework supports the usage of Data Annotations. Data Annotations are used for validation purposes and also for mapping definitions between code and columns in the database.

All annotations are implemented as attributes which can be found in the System.ComponentModel.DataAnnotations  namespace (same attributes that are used for ASP.NET MVC validation purposes).

Common attributes:

  • [Key] – Column(s) that define the Primary Key in the database table
  • [StringLength] – Minimal and maximal string length (only used for validation purposes not as database constraints)
  • [MaxLength] – Can be used instead of [StringLength] to just define the maximal string length of a column
  • [ConcurrencyCheck] – Flag that indicates that concurrency checks are activated for the column 
  • [Required] – Flag that indicates that a value is required for the column (column is flagged as not null)
  • [Timestamp] – Flag on time stamp columns which is used for concurrency checks
  • [Column] – Specify the name of a column (default property name), can also be used to define the column position
  • [Table] – Specify the name of a table (default class name)
  • [DatabaseGenerated] – Flag that indicates that the value is filled by the database (possible values are Computed, Identity, None)
  • [NotMapped] – Is used to define a property in the class that does not get generated in the database.
  • [ForeignKey] and [InverseProperty] – Column(s) that are defined as Foreign Keys

Following an example for the usage of Data Annotations that was applied to our company domain. The Manager class does not currently contain any properties that could automatically be identified as primary key.

By adding the [Key] attribute to the ManagerCode property you define that this property should act as primary key. You furthermore add a concurrency check as well as a minimum and maximum length setting for the Name property.

image

In the following example we add a required constraint to the Department class by applying the [Required] Data Annotation to the Name property.

image

Data Annotations are definitely easy to use but it  is preferable to use a programmatic approach that provides much more flexibility.  This approach is based on the Code First Fluent API.

You have to implement the OnModelCreating method within the derived CompanyContext class. Then you define your constraints applicable to your domain within this method programmatically.

image

When using this approach you may even describe relations between tables and columns. The following code example defines that the Manager entity contains a Department entity. The key that relates both is the DepartmentId.  If the Manager entity is deleted then the corresponding Department must also be deleted  (CascadeOnDelete).

image


Share/Save/Bookmark

Monday, July 25, 2011

[Tutorial] Code First with Entity Framework 4.1
Part1: Introduction to the Code First approach

This tutorial introduces the new functionalities that were added to Entity Framework 4.1. It shows the differences between the approaches and acts as an introduction to these new features.

Database First & Model First

The Database First approach is interesting when the database already exists. You use Visual Studio and the Entity Framework Designer to generate the C# and VB.NET classes which reflect the existing database model.

You may then change relations and structures using the Designer (or the XML mapping files) to further optimize the model. The priority is the database - the code and the model are only secondary.

The Model First approach is important when you begin from scratch. You start with the entity model and use the Entity Framework Designer to design the relations and the entities.

Then you generate the C# and VB.NET classes and also the database from within Visual Studio. The priority is the model - the code and the database are only secondary.

Code First

When your priority is the code and you want to begin from scratch without any existing schemas or XML mapping files using source code, then the approach is called Code First.

You simply create your domain classes and Entity Framework 4.1 will easily allow to use them with the database and the future model.

You use a context and are able to execute Linq2Entities queries in no time ! You may even take advantage of the change tracking features !

Entity Framework handles all of the background work and manages the interaction with the database. All the classes that are used during runtime are auto-generated.

In this case the configuration is not read from XML files but instead read from the configuration of the DbContext object in memory.

Code First allows:

  • Developing without the need to use the Designer or XML mapping files
  • Defining the objects of the model based on a POCO (Plain Old CLR Objects) approach

Explanation:

  • Design and implement a company domain with Managers, Collaborators and Departments.

Fig1_ClassDiagram

  • Create your classes using a standard object oriented approach and using inheritance when appropriate.
  • Use the POCO approach for your classes where possible.
  • Note that for being able to use the auto-mapping feature for the primary keys you need to have named your class properties like this : [Classname]Id.

image

  • Entity Framework 4.1 allows connecting those POCO classes with the database very easily by using the ObjectContext class (and in particular the DbContext class).

image

  • The last step consists of defining the connection to the database within the web.config or app.config files. Note that EF will search for the connection string that has the same name as the class that was inherited from the DbContext class. You may however define a different name ("CompanyContext" in our example).
image
Share/Save/Bookmark

Monday, July 18, 2011

[Tutorial] Common Design Patterns in C# 4.0
Part8: Bridge Pattern

Pattern Name:
Bridge Pattern

Short Description:
Separate implementation and object interfaces

Usage: 
Sometimes used, useful to decouple an abstraction from its implementation and to be able to modify them independently.

Note that the Bridge pattern has nearly the same structure as the Adapter Pattern. But it is used when designing new systems instead of the Adapter pattern which is used in already existing systems.

Complexity:
1 / 5

UML Class Diagram:

image

Explanation:

  • The abstract Repository class defines the interface that all inheriting refined Repository classes will use for object management purposes.
  • Note that the operations within the Repository classes define high-level operations.

image

  • The refined Repositories extend the basic functionalities and implement the execution code that uses the implementation classes. They should contain specializations which only apply to specific Repositories. 

image

  • The abstract DataObject class defines the interfaces of the implementation classes. Note that the abstract Repository and the abstract DataObject classes can have completely different interfaces.
  • The concrete DataObject implementations contain the code that executes all the low-level operations.
  • Note that the methods within the Repository class could also call multiple methods in the implementation classes (1 to * relationship).

image

image

  • In the last step we add some code to test the software design and the Bridge implementation.

image

  • When running the example you can see that everything is working as expected and that the correct classes are instantiated during runtime.
image
Source Code:
http://csharpdesignpatterns.codeplex.com/

Share/Save/Bookmark

Friday, July 1, 2011

[Tutorial] Common Design Patterns in C# 4.0
Part7: Adapter Pattern

Pattern Name: 
Adapter Pattern

Short Description:
Match interfaces of classes with different interfaces

Usage:
Often used and easy to implement, useful if classes need to work together that have incompatible existing interfaces.

Complexity: 
1 / 5

UML Class Diagram:

image

Explanation:

  • The TradingDataImporter class acts as a client using classes with an existing Connector interface.

image

  • The abstract Adapter class defines the interface that the client class knows and that it can work with.
  • The concrete Adapter classes convert the interface of the incompatible classes into an interface the client expects. They make different existing interfaces work together.

image

  • Here are some examples of different adaptee classes that implement different interfaces. However, the client expects a generic interface that they currently don’t provide. That is why they get wrapped by the concrete adapter classes to make them compatible with the client.

image

  • In the last step we add some code to test the software design and the Adapter implementation.

image

  • When running the example you can see that everything is working as expected and that the correct classes are instantiated during runtime.
image

Source Code:

http://csharpdesignpatterns.codeplex.com/


Share/Save/Bookmark

Wednesday, June 8, 2011

[MS Days 2011] Slides of Windows Azure Session Online

Below the slides that I used for my session during the MS Days in Grenoble. The session and slides were done in French.


Share/Save/Bookmark

Wednesday, June 1, 2011

[Publication] Article in French Programmez Magazine on Entity Framework 4.1 and CodeFirst

You can find an article of 5 pages concerning Entity Framework 4.1 and CodeFirst in the French Programmez magazine No.142 written by me and Fathi Bellahcene.

image

First Page and Second Page (low resolution)

Third Page and Fourth Page (low resolution)

Fifth Page (low resolution)

The article is written in French but as always I will write some English articles on my Blog in the next weeks. So stay tuned if you are interested in getting to know the new features of Entity Framework 4.1 and the CodeFirst approach.

You can find the source code here:
http://codefirst.codeplex.com


Share/Save/Bookmark

[Tutorial] Common Design Patterns in C# 4.0
Part6: Singleton Pattern

Pattern Name:
Singleton Pattern

Short Description:
Class with only one single possible instance

Usage: 
Often used for objects that need to provide global access with the constraint of only one single instance in the application

Complexity:
1 / 5

UML Class Diagram:

image

Explanation:

  • There are multiple ways of implementing the Singleton Pattern in C#. I am going to explain the most efficient approaches that also provide thread safety.
  • Note that in the first example the default constructor is defined as private so that it is not possible to instantiate the object from the outside. The class is also marked as sealed which means that inheritance is not allowed for it.
  • The internally instantiated object is stored in a private variable that is marked as static. The public static property GetInstance is used to allow access to this object. It contains the business logic that assures that only a single instance can ever exist.
  • To achieve this behavior a lock strategy is used to assure that only a single thread is allowed to do the null check and create a new instance if it does not already exist.
  • A test function DisplayConfiguration() was added to be able to verify the class design.

image

  • Note that in the second example the default constructor is also defined as private so that it is not possible to instantiate the object from the outside. The class is also marked as sealed which means that inheritance is not allowed for it.
  • This time a private nested class is used to provide access to the instance that must only exist once in the application.
  • This nested class has a static default constructor and an internal static read-only instance of the object. Only the container class has access to the instance which will due to the software design (auto-instantiated and marked as read-only) only exist once.
  • A test function DisplayRules() was added to be able to verify the class design.
  • I recommend using this example as your default approach for your Singleton implementations since there is no locking in it which makes it more efficient in terms of performance.

image

  • In the last step we add some code to test the software design and the Singleton implementation.

image

  • When running the example you can see that everything is working as expected (it is however not as simple to test that there really is just one single instance, you just have to believe in the correct software design).
image


Source Code:

http://csharpdesignpatterns.codeplex.com/


Share/Save/Bookmark

Tuesday, May 17, 2011

[C# and Language] Compiler as a Service (CaaS)

Lately I showed you the new async features of the next version of C# 5.0, which are already quite compelling. But Microsoft is already working on the language features that will come after the next version. These features are called Compiler as a Service (CaaS).

Everything is still in very early stage so I cannot give you any exact information, but I may give you the concepts and ideas behind it.

It will be possible to evaluate expressions at runtime and to inject them into your code. This allows for very interesting scenarios where parts of your business logic and business rules may be stored outside of your code (in the DB or in XML file for example) and be modified an extended independently.

An example could be:

image

Other use cases consists of having the possibility to translate from one language into another very easily from within Visual Studio. You could for example select code parts in C# and choose F# as the language to translate to. The CaaS feature would then scan the C# code and generate the corresponding F#  code.


Share/Save/Bookmark

Sunday, May 8, 2011

[MS Days 2011] Speaker at Microsoft Days 2011 in Grenoble
Session on Windows Azure

I am going to be speaker and animate a session with Fathi Bellahcene on Windows Azure during the Microsoft Days 2011 in Grenoble the 7th June ! So if you have the time and if you are around don’t hesitate and come to see us in action !

image


Share/Save/Bookmark

Saturday, May 7, 2011

[Tutorial] Common Design Patterns in C# 4.0
Part5: Prototype Pattern

Pattern Name:
Prototype Pattern

Short Description:
Clone or copy initialized instances

Usage: 
Easy pattern, usage depends on the preferred software design, provides an alternative to the other creational patterns that are mainly based on external classes for creation

Complexity:
1 / 5

UML Class Diagram:

image

Explanation:

  • The abstract prototype class defines the interface that contains a clone method for cloning itself.

image

  • The inherited classes implement the clone function. Note that C# provides two different ways of cloning an object: by shallow copy (only top level objects) or by deep copy (all objects). 
  • You could also manually create a new object and set its values with the values of the original object but since C# already implements everything necessary I advise using that.

image

  • The client class does not create new objects itself. Instead it asks the objects to clone themselves when needed. The cloned objects are perfect copies and contain all values of the original objects depending on the shallow or deep copy approach (see above).

image

  • You may also use the ICloneable interface that already exists in C#

image

  • In the last step we add some code to test the software design and the Prototype implementation.

image

  • When running the example you can see that everything is working as expected and that the correct classes are instantiated during runtime.

image

Source Code:
http://csharpdesignpatterns.codeplex.com/


Share/Save/Bookmark