Posted in .Net Basics, Database, SQL Server

Database Performance Tips

As a developer, you may or may not need to go into the database and write queries, or design tables and indexes, or help determine configuration of your SQL Server systems. But if you do, these tips should help to make that a more pain free process.

ORM Tips:-

More and more people are using Object to Relational Mapping (ORM) tools to jump the divide between application code that is object oriented and a database that stores information in a relational manner. These tools are excellent and radically improve development speed, but there are a few ‘gotchas’ to know about Continue reading “Database Performance Tips”

Advertisements
Posted in .Net Basics, ADO.Net, C# 4.0, Microsoft

Entity Framework 5 is released

Microsoft has just release a latest version of Entity Framework, version 5. EF5 is available as the Entity Framework NuGet package and is also included in Visual Studio 2012.

below is the some useful information from ADO.Net Blog

What’s New in EF5

EF 5 includes a number of new features and bug fixes to the EF4.3 release. Most of the new features are only available in applications targeting .NET 4.5, see the Compatibility section for more details.

  • Enum support allows you to have enum properties in your entity classes.
  • Spatial data types can now be exposed in your model using the DbGeography and DbGeometry types.
  • The Performance enhancements that we recently blogged about.
  • Code First will now detect if you have LocalDb or SQL Express available for creating new databases. Visual Studio 2012 includes LocalDb, whereas Visual Studio 2010 includes SQL Express.
  • Code First will add tables to existing database if the target database doesn’t contain any of the tables from the model.

The EF Designer in Visual Studio 2012 also has some new features:

  • DbContext code generation for new models means that any new models created using the EF Designer will generate a derived DbContext and POCO classes by default. You can always revert to ObjectContext code generation if needed. Existing models will not automatically change to DbContext code generation.
  • Multiple-diagrams per model allows you to have several diagrams that visualize subsections of your overall model. Shapes on the design surface can also have coloring applied.
  • Table-Valued functions in an existing database can now be added to your model.
  • Batch import of stored procedures allows multiple stored procedures to be added to the model during model creation.

Get Started @ msdn.com/data/ef

The updated EF MSDN site includes a bunch of walkthroughs and videos to get you started with Entity Framework, including the new features in EF5.

What Changed Since the Release Candidate

You can see a list of bugs that we fixed since the EF5 RC on the EF CodePlex site.

The most notable change since RC is that new models created using the EF Designer in Visual Studio 2012 will now generate a derived DbContext and POCO classes by default. You can always revert to ObjectContext code generation if needed.

Compatibility

This version of the NuGet package is fully compatible with Visual Studio 2010 and Visual Studio 2012 and can be used for applications targeting .NET 4.0 and 4.5.

Some features are only available when writing an application that targets .NET 4.5. This includes enum support, spatial data types, table-valued functions and the performance improvements.

Need Help

Head to the EF MSDN site to find out how to get help with Entity Framework.

Thank you Entity Framework Team for this update..

 

 

Posted in .Net Basics, Microsoft

Microsoft launced Outlook.com – Future of Hotmail

Microsoft has introduced Outlook.com as a new email services which will replace old Hotmail !!

With Hotmail no longer the ‘hottest’ email service in the town, Microsoft has launched Outlook.com, a new web mail service, to take on Google’s extremely popular Gmail. The new email service comes with “virtually unlimited” storage and integrates Skype, the popular video chat service that Microsoft bought last year.

Like other email services, Outlook.com too will serve advertisements to their users. Though Microsoft is saying there would not be display advertisements based on email content. They will not scan content of email of attachments. Hope for the add free interface.

Outlook is the name of the native email client that Microsoft has bundled with Office suit for years. Microsoft claims that Outlook is world’s most used desktop email client.

All current users of Hotmail can log in to Outlook.com using their existing Ids, not sure though for how long Hotmail would be available.

Outlook.com has been designed using Microsoft’s Metro users interface. “The fresh, clean user interface gets the clutter out of a user’s way. It looks very neat and clean.

Meet Outlook.com Preview here.

All the existing users of Hotmail enjoy the new interface.. I would post some more details after exploring this.

Posted in .Net Basics, C# 4.0

Memory management in Microsoft dotnet (.Net)

Hello everyone,
Today I came across a good resource on memory management in Microsoft .Net, so I would like to share this with all..

on website of Red-gate I found some videos, click here to see them.

Posted in .Net Basics, C# 4.0

Abstract Classes in .Net

An abstract class means that, no object of this class can be instantiated, but can make derivations of this.

Its a special type of class that cannot be instantiated. (So why we need that ??) There are some reasons, an Abstract class is only to be sub-classed. That means it enforces some contracts or say methods to all the subclasses.

Here is a basic sample of abstract class and how to access their abstract and non abstract methods.

abstract class testDemo
    {
        public void callme() // non abstract method
        {
            // Some implementation
        }

        abstract public void ImplementMe(); // abstract method
    }

    class Child : testDemo
    {
        //implement the abstract method
        public override void ImplementMe()
        {
            throw new NotImplementedException();
        }
    }

This is how you can access methods of the abstract class.

 public void TestMethod()
        {
            Child obj = new Child();
            obj.callme();       // call to a non abstract method
            obj.ImplementMe();  // call to an abstract method which is implemented on the Child class
        }

An abstract class can also have abstract properties as well, derived class has to implement this property.

An Abstract class cannot be a sealed class. Following is not valid

  abstract sealed class testDemo {}

An abstract Method cannot be Private. Access modifier of the abstract method must be the same in both abstract class and its derived class. Otherwise it will be detected as error by compiler.

private abstract int myProp(); // incorrect

An Abstract method can’t be virtual as it is implicitly virtual.

An abstract member can’t be static but an abstract method can be a static one.

Hope this help someone.

Posted in .Net Basics, C# 4.0

yield in C#

yield – another useful tool in C#. This keyword is used in a combination with return.

What it does basically ??

It is helpful in the iterations like for and foreach. You can only use this on enumerators, such as one that returns IEnumerable. You can use it to “save the state” of the function after the return. After the yield is reached, and the value is returned, the foreach loop will call the function again, but you will pick up right where you left off. Let me show you this with an example:

public class MyList
{
    //using System.Collections;
    public static IEnumerable<int> GetPower(int number, int exponent)
    {
        int counter = 0;
        int result = 1;
        while (counter++ < exponent)
        {
            result = result * number;
            yield return result;
        }
    }

    static void Main()
    {
        // Display powers of 2 up to the exponent 9:
        foreach (int i in GetPower(2, 9))
        {
            Console.Write("{0} ", i);
        }
    }
}
/*
Output:
2 4 8 16 32 64 128 256 512
*/

Please note the use of generic and define the return type as enumerable of int type, this performs well as it avoid boxing and unboxing of the object the loop is returning. If you use only IEnumerable it will do box-unbox at the time of returning the element.

The yield keyword signals to the compiler that the method in which it appears is an iterator block. The compiler generates a class to implement the behavior that is expressed in the iterator block. In the iterator block, the yield keyword is used together with the return keyword to provide a value to the enumerator object. This is the value that is returned, for example, in each loop of a foreach statement.

Practically useful ??

Yes, you can use yield in several ways. For example, you can use it as a filter for displaying random HTML code in your ASP.NET website. Internally, you can select random elements from an array and yield them, such as for advertisements.

It also used with the “break” keyword.

I hope this help someone.

For more details yields in C# Reference on MSDN.

Posted in .Net Basics, C# 4.0

dynamic type in C# 4.0

The type dynamic was introduced with C# 4.0 long back but I have used this very recently in one of my project, so just want to share my experience with this wonderful feature of C# 4.0.

dynamic

The dynamic type enables the operations in which it occurs to bypass compile-time type checking. Instead, these operations are resolved at run time. It behaves like type object in most circumstances, however the operations that contain expressions of type dynamic are not resolved or type checked by the compiler.

Variable of type dynamic is compiled into variable of type object, and that is why the dynamic type is exists at compile time but not at runtime.

How to use dynamic – a simple example:

class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}

output:

System.Int32
System.Int32

you will see the output returns the same type as both the variables are having int value assigned. If you want to see the difference between dyn and obj at compile time, try following lines and compile the code.

dyn = dyn + 3;
obj = obj + 3;

The compiler raised an error for attempted addition of an integer and an object in expression obj + 3. But, no error is reported for dyn + 3. The expression that contains dyn is not checked at compile time because the type of dyn is dynamic.

For more information about the dynamic type http://msdn.microsoft.com/en-us/library/dd264741(VS.100).aspx and Using Type dynamic 

Posted in .Net Basics

Generics in C# .Net

When we look at the term “Generic”, unrelated to our programming world, it simply means that it is not tied to some predefined type and in programming terminology:

Generics allow you to define type-safe classes without compromising type safety, performance, or productivity.

In our programming world, “Generic” provides the functionality to handle any Type in generic and Type safe manner. That means we can have a single array class that we can use to store a list of Employee or a list of Items, and at the time of using them, we’ll be able access them in the collection directly as a list of Employee or Items, and not as Object. That means we don’t need to do boxing/unboxing or casting, which in turn gives us a performance boost.

Continue reading “Generics in C# .Net”

Posted in .Net Basics

Release Managed & Unmanaged Resources

The basic difference between a managed and unmanaged resource is that the garbage collector knows about all managed resources, at some point in time the GC will come along and clean up all the memory and resources associated with a managed object. The GC does not know about unmanaged resources, such as files, stream and handles, so if you do not clean them up explicitly in your code then you will end up with memory leaks and locked resources.

Continue reading “Release Managed & Unmanaged Resources”