Showing posts with label What's New. Show all posts
Showing posts with label What's New. Show all posts

Saturday, August 17, 2013

New Features of Entity Framework 6



Introduction

In this article I provide some exciting and useful features of Entity Framework 6 beta release. Currently EF 6's beta release is available. The Beta release can be downloaded from NuGet. These features will be really useful and when the final release is available you will really find them useful and more powerful than the previous versions. So without wasting time I will proceed to discussing some key features.

  1. Asynchronous pattern Support The .NET Framework 4.5 introduced the Task-Based Asynchronous Pattern that uses the async modifier and the await operator to provide asynchronous programming. This feature is now supported by EF6. So database calls that fetch a large amount of data, made through EF can be processed asynchronously. By using the asynchronous pattern we can avoid blocking the responsiveness of our application.

    Let's have at look some code snippets without and with the asynchronous pattern and how to use this pattern with EF6.

    a. Without Asynchronous Patterns
     
    privatestatic void SaveInput(string question,string answer)
    {
        using (var ctx = new AnswersContext())
        {
            ctx.Questions.Add(new Question()
            {
                Content = question,
                Answers =new List<Answer> { new Answer { Content = answer } }
            });
            ctx.SaveChanges();
        }
    }

    b. With Asynchronous Patterns
    privatestatic void PrintQuestions()
    {
        using (var ctx = new AnswersContext())
        {
            foreach (var q in ctx.Questions)
            {
                Console.WriteLine(q.Content);
                foreach (var a in q.Answers)
                {
                    Console.WriteLine(" -" + a.Content);
                }
            }
        }
    }

    As you can see, I have used async and await, two new keywords. If we are using the await operator then it is necessary to use async with the method signature. Since we are calling the ToListAsync method, as soon as this method is called, the thread won't block until the task finishes.
     
  2. Custom ConventionsWhen we use the code first approach in Entity Framework, classes are mapped with the database using a set of conventions that are defined in EF, such as which property becomes the primary key, which name of in the table maps with an entity name etcetera. We must use some custom code conventions for that. Sometimes these default conventions are not perfect for our model and we must do configuration using Data annotation and other ways.
     
  3. Code First Mapping to Insert/Update/Delete Stored Procedures When we use code first entities, it is easy to select data using Stored Procedures but there was no way to delete, update and insert data using Stored Procedures.

    EF 6 provides this ability to insert, update and delete using a Stored Procedure. So you can do that as in the following:
     
    mBuilder .Entity<Users>() .MapToStoredProcedures(s => {
    s.Update(u => u.HasName("modify_User"));
    s.Delete(d => d.HasName("delete_User"));
    s.Insert(i => i.HasName("insert_User"));
    });
     
  4. Connection ResiliencySince we know that currently most database servers are a cloud, such as an Azure Database. So the chances of connection failures are greater. This could be because of some defensive techniques used by the cloud database because of how the cloud database maintains its consistency, so to maintain that, sometimes it closes the connection explicitly.

    EF 6 provides many ways to retry actions to be performed on the database and to minimize the number of failures and the effect of defensive code. Even users can create their own retry strategies and decide which action should be performed if an exception occurs.
     
  5. Better supports of POCO entitiesNow we can make nesting of entities and complex types inside classes. We can also have Custom Equal and GetHashCode Method implementations.
     
  6. Multiple Context Per DatabaseIn EF 5, when we use Migration or a Code first database created automatically then we can have only one code first model per database. But In EF 6 , we will be able to have multiple code first models per database.
     
  7. Default Isolation levelDefault isolation level has been changed for databases created using code first in EF6. In EF 5 it was Serializable so now it has been changed to READ_COMMITTED_SNAPSHOT. So because of this isolation level the database becomes more scalable and there are very few chances of deadlock.
     
  8. Supports Enum and Spatial data types :EF 6 now provides support of Enum and Spatial Data Types.
     
  9. Now easy to set default schema at one placeEF 6 provides the DbModelBuilder.HasDefaultSchema Code first API that allows configuration of a default database schema for the code fist model in one place. Previously this default schema was hard-coded to dbo and if we needed to change it , we needed to do a lot of work.

Summary

In this article I have discussed some key features that have been introduced in the Beta release of Entity Framework 6 . There are many other features also introduced in EF 6. For more information you can refer to the following Codeplex website. 

Friday, August 16, 2013

What's New in Windows Workflow Foundation in .NET 4.5?




Part I
During the last //build/ conference a number of new WF4, or should I now say WF4.5, features where announced. While the list of new features isn’t earth shattering long some of the most annoying shortcomings where addressed.
Designer enhancements
As a developer I spend a lot of time in the designer so any improvements there are going to make me happy. And I am very happy to see some of the new features.
Auto surround with a Sequence.
This seemingly small feature is a real time saver. There are lots of places where an activity has a child activity to execute, for example an If activity has a Then and an Else and executes either. These are of type Activity so by default you can add a single activity there. At runtime this is no problem. Want multiple child activities? Just add a Sequence and you can add as many child activities as you want. The problem is that in the designer that means removing the existing child (you can put it on the clipboard), adding a sequence and finally re-adding the original child. Not difficult but somewhat cumbersome and I never like deleting something I need and saving it on the clipboard.
No longer.  Now we can just drag a new Activity and the designer will automatically wrap the existing activity in a Sequence. So much easier and a much nicer way to work!
Annotations
Another feature I missed greatly was adding comments to an Activity describing its intent. All we had was the DisplayName and that was not much of a replacement. Fortunately we now get Annotations allowing us to add more information about the intent.
Search
Searching through workflows is another big one. With small workflows it is quite easy to see where a variable is used but when workflows get bigger this becomes an increasingly hard problem. With WF4 I typically solve this by opening the workflow XAML in a text editor and searching the raw XML. While this works reasonably well it is less that perfect and one of those tricks you need to pick up while working with WF4. The new search capability will let you search through a workflow in the designer, as you really should, just as any other Visual Studio artifact. Another great improvement.
Multi-select of activities
As soon as you start creating flow chart or state machine workflow you will quickly find you have to rearrange the existing activities to make place for a new one. Seems simple enough to move them right? Well you are wrong as the designer only lets you select a single activity at the time so you can’t move a group of them in one go.
Well no longer as we can now select multiple activities and drag them around as a group.
This is by no means the complete list of changes, here you can find a more complete list, but these are the ones I think most people, myself included, where really missing. Glad to see them being added, now if only we could get to work with them today.

Part II
During the last //build/ conference a number of new WF4.5 features where announced. In part 1 I took a look at the designer improvements, here I am going to take a look at some of the runtime enhancements.

Runtime Enhancements
New activities
As part of WF 4.5 we will see some new activities in the box. The number isn’t earth shattering but as I always tell people WF activities are all about your business and Microsoft can’t create activities tailored to your business, you need to do so yourself.
One useful new activity is the NoPersistScope. Not that it is very hard to create yourself once you know how, I wrote a blog post about it here, but not easy to discover and certainly something that is very useful.
State machine
Although not completely new, it was released as part of the .NET 4 platform update 1, the state machine is now rolled into the .NET framework proper so it doesn’t require an additional install. Nice to see that back.
C# Expressions
One thing a lot of developers are going to be very happy with is support for C# expressions. Previously you where forced to use VB expressions, even in a C# project. And while that isn’t extremely hard it did require a mental switch and, as most C# developers aren’t fluent in VB, some frequent searching for the right syntax. With WF 4.5 you can enter you expressions using the C# syntax in a C# project and in VB syntax in a VB project. So much better.
Besides C# expression it appears we can also replace the expression authoring experience with something we control using new extensibility points in the designer. So far I have not seen any details of this so I am curious to what kind of scenarios this opens up.
Versioning
The most important new feature is workflow versioning. In Part III - I will go into details on what this new feature brings us.

Part III
This section is about one of the biggest missing pieces which is versioning workflows.  See also part I about the designer enhancements and part II about the other runtime enhancements.


Versioning Workflows
 
To understand why this is so painful at the moment it is important to remember that workflow instances often run for a long time. And that is not just a long time in computer terms, like a few minutes, but a long time in human terms like weeks, months or even years.
Right not with WF4 you can’t change the definition of a workflow instance that is running even when it is persisted to disk. Doing so will result in any number of weird exceptions when the workflow tries to resume. And the fact that you can’t change the definition means you can’t fix a bug, all you can do is let the workflow run and make sure that new instances are started with a fixed definition. Not the nicest of situations and I am very glad this is being addressed.

The first part is the ability to add a version to a workflow instance using a WorkflowIdentity object. This doesn’t fix the versioning issue itself but at least we get a predictable exception.

The second part if the capability to create update maps and update the state of a persisted workflow instance to a newer version. This capability gives us a lot of control as we can choose which workflow instance we upgrade and which we keep at the current version. Basically we create a DynamicUpdateMap and use the DynamicUpdateServices.PrepareForUpdate() to update a workflow instance state. A great and long awaited addition to the workflow runtime.

The final versioning piece is an addition to the WorkflowServiceHost allowing it to host multiple versions of a workflow. This is something we can now achieve using the WCF routing service but is far from trivial to implement. This should make the scenario of versioning workflow services much easier.


What's New in BizTalk Server 2013?




Improve performance

  • Host handler association of dynamic send ports
  • Minimal Lower Layer Protocol (MLLP) adapter improvements
  • Multifold improvements in ordered send port scenarios
  • XslCompiledTransform in maps

Connect to the cloud

  • Hybrid application support 
  • Connection to Windows Azure Service Bus and Windows Azure Storage
  • REST support
  • Microsoft SharePoint Online
  • Windows Azure Active Directory Access Control service

Run in the cloud

  • Reduce hardware procurement time
  • Set up and configure BizTalk environment in minutes
  • Pay for use
  • Integrate with Windows Azure Management Portal

Support the latest technologies and standards

  •  Windows Server 2012, Microsoft Visual Studio 2012, Microsoft SQL Server 2012, Microsoft System Center 2012, the latest version of Microsoft Office
  •  SAP 7.2 and 7.3, Oracle Database 11.2, Oracle E-Business Suite 12.1, Oracle Siebel 8.1
  • Health Level Seven (HL7) 2.5.1 and 2.6
  • Society for Worldwide Interbank Financial Telecommunication (SWIFT) 2012 Message Pack
  • X12 5030, EDIFACT D05B

Simplify experience

  • Viewable artifact dependencies
  • Simplified setup and configuration of Enterprise Service Bus (ESB)
  • Simplified installation of SharePoint adapter
  • Secure file transfer (SFTP)
  • Connector for IBM Informix and DB2 DRDA
  • Web-based administration and deployment for Microsoft Transaction Integrator (TI)