Thursday, May 26, 2011

Static Classes and Static Members

http://msdn.microsoft.com/en-US/library/79b3xss3(v=VS.80).aspx

Static Classes

 
The main features of a static class are:


Static Members

A static method, field, property, or event is callable on a class even when no instance of the class has been created. If any instances of the class are created, they cannot be used to access the static member. Only one copy of static fields and events exists, and static methods and properties can only access static fields and static events.

Static Constructors

/*
 *  Non-static classes can have both static and non static constructors.
 *  A non-static class must have a non-static default constructor. If it is not provided, it is provided
 *  by the compiler.
 *  A non-static class may optionally declare a  static constructor. It will be called before the first instance
 *  of the non-static class is created. The static constructor can only be used to initialize static members.
 *  If a non-static class  declares a static constructor only,
 *  then the compiler provides a default parameterless non-static constructor.

 * * Access modifiers are not allowed on static constructors. (public/private/etc), because they are called by the framework. They are not
 * user callable (cannot be called explicitely).
 *
 *
 *  Static constructors cannot act on instance members, because static constructor is always called before any instance of
 *  the class exists.
 *  Static constructors are called once only, they are not called on every instance creation.
 *  A class's static members cannot be accessed with an  instance reference, they must be qualified with a type name instead.
 * 
 * You can have two parameterless constructors for a class , one static and one non-static. They will have same signatures
 * including same name, except one will have static keyword and no access specifier. However, you CANNOT have two methods with
 * same name and signatures, with one as static and one non-static.
 *
 * Static members (data members) persist their values across all instances of the class.
 * Static methods can be accessed without instantiating the class.
 *
 *
 *
 * MSDN==================================================================
 * Link : http://msdn.microsoft.com/en-us/library/k9x6w0hc(v=VS.100).aspx
 *
 * Static constructors have the following properties:
A static constructor does not take access modifiers or have parameters.
A static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced.
A static constructor cannot be called directly.
The user has no control on when the static constructor is executed in the program.
A typical use of static constructors is when the class is using a log file and the constructor is used to write entries to this file.
Static constructors are also useful when creating wrapper classes for unmanaged code, when the constructor can call the LoadLibrary method.
If a static constructor throws an exception, the runtime will not invoke it a second time, and the type will remain uninitialized for the lifetime of the application domain in which your program is running.
 * MSDN==================================================================
 */



A very good article on constructors can be found  at:

http://dhondiyals.wordpress.com/2010/02/25/constructor-in-depth/




Some excertps from this article :

Constructors:
- Constructors cannot be “virtual”.
- They cannot be inherited.
- Constructors are called in the order of inheritance.
- Constructors can be overloaded.
- special function that is called when class is instantiated.
- same name as the class.
- does not have a return type.
- used to initialize values.
- can have parameters.
- compiler will supply one if not declared.

As per the C# specification, a constructor can have the following modifiers.
public
protected
internal
private
extern

There are three types of constructors in C#
a.Instance Constructors
b.Private Constructors
c.Static Constructors


A static constructor is used to initialize a class.It is not used to initialize instance of a class.
1. A static constructor must always be parameterless.
2. Since it cannot have parameters,a static constructor cannot be overloaded.
3. Access modifiers are not allowed on static constructors. 
4. A Static constructor cannot be inherited.
5. A static constructor cannot be called explicitly.It is called automatically(implicitly). If a class does not define the entry point Main() method,then the execution of a static constructor is triggered automatically by the first of the following events to occur within an application domain.   
 (Case – A) An instance of the class is created.
 (Case – B) Any of the static members of the class are referenced.
6. If a class contains the entry point Main() method,then the static constructor for that class executes automatically before the Main method is called within an application domain.
7. The static constructor for a class executes at most once in a given application domain.
8. If a class contains any static fields with initializers, those initializers
are executed prior to the execution of static constructor.
9. If a class contains any static fields with out initializers,then those static fields are initialized with default values prior to the execution of static constructor.
See the example of 5
The class AClass of example 5 has a static field ‘aStaticField’. ‘aStaticField’ is not intialized explicitly. So it is automatically intialized with the  default value 0 prior to the execution of static constructor
10. Like static methods, we cannot access a nonstatic field,method or property with in a
static constructor.
11. Static Constructor Executes Before an Instance Constructor
12. Static Constructor Can Access Only Static Members

Friday, May 20, 2011

Float Sorting Problem in GridView

Requirement : Display a float value in the format XXXX.XX. Also it must be formatted.

If we format this numer in SQL and return a formatted string, we lose the sorting functionality.
e.g nos will be displayed as

1.0
21.22
3.12

. To get correct result, return float as it is from SP and use DataFormatString="{0:F2}" in the
boundcolumn declaration in the gridview

Float Sorting Problem in GridView

Requirement : Display a float value in the format XXXX.XX. Also it must be formatted.

If we format this numer in SQL and return a formatted string, we lose the sorting functionality.
e.g nos will be displayed as

1.0
21.22
3.12

. To get correct result, return float as it is from SP and use DataFormatString="{0:F2}" in the
boundcolumn declaration in the gridview

Wednesday, May 18, 2011

what is context.createquery method in LINQ




using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    string queryString =
        @"SELECT VALUE contact FROM AdventureWorksEntities.Contacts
            AS contact WHERE contact.FirstName = @fn"
;

    ObjectQuery<Contact> contactQuery =
        context.CreateQuery<Contact>(queryString,
            new ObjectParameter("fn", "Frances"));

    // Iterate through the collection of Contact items.
    foreach (Contact result in contactQuery)
        Console.WriteLine("First Name: {0}, Last Name: {1}",
        result.FirstName, result.LastName);
}

Tuesday, May 17, 2011

data access options in vs 2008 ADO.NET Entity Framework Essential Resources

http://www.renaissance.co.il/downloads/Entity%20Framework%20Essential%20Resources.pdf





 Overview and Introduction http://msdn.microsoft.com/en-us/data/aa937723.aspx
http://msdn.microsoft.com/en-us/library/bb399572.aspx
The ADO.NET Entity Framework and Entity Data Model http://www.renaissance.co.il/downloads/Entity%20Framework%20and%20EDM.pdf An Entity Data Model for Relational Data Part I: Defining the Entity Data Model http://www.code-magazine.com/articleprint.aspx?quickid=0712062 An Entity Data Model for Relational Data Part II: Mapping an Entity Data Model to a Relational Store http://www.code-magazine.com/Article.aspx?quickid=0712032 Introducing ADO.NET Entity Framework http://www.code-magazine.com/Article.aspx?quickid=0711051 Achieve Flexible Data Modeling With the Entity Framework http://msdn.microsoft.com/en-us/magazine/cc700331.aspx Programming Against the ADO.NET Entity Framework http://www.code-magazine.com/Article.aspx?quickid=0712042 Data Access Options in Visual Studio 2008 http://www.code-magazine.com/Article.aspx?quickid=0809091 Entity Framework- The Crib Sheet http://www.simple-talk.com/dotnet/.net-framework/entity-framework-the-cribsheet/ Entity Framework FAQ http://blogs.msdn.com/dsimmons/pages/entity-framework-faq.aspx Videos How Do I? Videos - Entity Framework Series http://msdn.microsoft.com/en-us/data/cc300162.aspx Dan Simmons on the Entity Framework Part 1 & 2 http://www.dnrtv.com/default.aspx?showNum=117 http://www.dnrtv.com/default.aspx?showNum=118 Programming LINQ and the ADO.NET Entity Framework Webcast http://tinyurl.com/6zl78h Beyond the Basics http://msdn.microsoft.com/en-us/magazine/cc700340.aspx
http://gupea.ub.gu.se/dspace/bitstream/2077/10462/1/gupea_2077_10462_1.pdf
http://blogs.microsoft.co.il/blogs/idof/archive/2008/08/20/entity-framework-and-lazy-loading.aspx http://thedatafarm.com/LearnEntityFramework/tutorials/using-stored-procedures-for-insert-update-amp-delete-in-an-entity-data-model/
http://www.objectsharp.com/devlounge/articles/2008/04/27/the-entity-framework-vs-the-data-access-layer-part-0-introduction.aspx
http://www.objectsharp.com/devlounge/articles/2008/05/06/the-entity-framework-vs-the-data-access-layer-part-1-the-ef-as-a-dal.aspx
Samples & Extensions http://code.msdn.microsoft.com/adonetefx http://www.learnentityframework.com/resources ADO.NET Entity Framework Query Samples http://code.msdn.microsoft.com/EFQuerySamples The Entity Framework forum http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=533&SiteID=1 Blogs http://blogs.msdn.com/dsimmons
http://blogs.msdn.com/efdesign/default.aspx
http://blogs.msdn.com/jkowalski/default.aspx
http://blogs.msdn.com/elisaj
http://www.thedatafarm.com/blog/
http://msmvps.com/blogs/matthieu/default.aspx
http://blogs.msdn.com/meek/default.aspx http://blogs.msdn.com/alexj/default.aspx
http://blogs.msdn.com/timmall/
http://blogs.msdn.com/diego/

What are dimensions, mesaures, and cubes ?


www2.cs.uh.edu/~ceick/DM/dm_cubes.ppt
 
 
nA data warehouse is based on a multidimensional data model which views data in the form of a data cube
nA data cube, such as sales, allows data to be modeled and viewed in multiple dimensions
nDimension tables, such as item (item_name, brand, type), or time(day, week, month, quarter, year)
nFact table contains measures (such as dollars_sold) and keys to each of the related dimension tables
 
 

What Are the Data Warehouse Analytics Components?

Commerce Server 2007
For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.
This section describes components of the Data Warehouse Analytics System.


http://msdn.microsoft.com/en-us/library/bb219339(v=cs.70).aspx

What Are the Data Warehouse OLAP Cubes?

Commerce Server 2007
For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.
Online analytical processing (OLAP) cubes are data structures that the Data Warehouse uses to contain the data that you import. The cubes divide the data into subsets that are defined by dimensions.
A dimension is the descriptive attribute of a measure. For example, a dimension might describe the number of transactions on your site. The number of transactions is a measure. The transaction and the products purchased are dimensions. The following illustration shows the relationship between cubes, dimensions and measures.


Bb219339.csmn_DWA_OlapCubess(en-US,CS.70).gif 

Comparing features of LangGraph vs CrewAI

LangGraph Orchestration vs CrewAI Orchestration The following table compares LangGraph and CrewAI orchestration across their menta...