Sunday, December 26, 2010

Partial Keyeword and C#

Partial Keyeword and C#
  • Partial keyword can be used with  class, struct, or interface
  • The partial keyword indicates that other parts of the class, struct, or interface can be defined in the namespace
  • All the parts must use the partial keyword.
  • All the parts must have the same accessibility, such as public, private, and so on.
  • If any part is declared abstract, then the whole type is considered abstract.
  • If any part is declared sealed, then the whole type is considered sealed.
  • If any part declares a base type, then the whole type inherits that class.
  • All the parts that specify a base class must agree, but parts that omit a base class still inherit the base type.
  • Parts can specify different base interfaces, and the final type implements all the interfaces listed by all the partial declarations.
  • Any class, struct, or interface members declared in a partial definition are available to all the other parts. The final type is the combination of all the parts at compile time.
  • At compile time, attributes of partial-type definitions are merged.
  • The following are merged from all the partial-type definitions:
    • XML comments
    • interfaces
    • generic-type parameter attributes
    • class attributes
    • member
Restrictions
  • All partial-type definitions meant to be parts of the same type must be modified with partial.
  • The partial modifier can only appear immediately before the keywords class, struct, or interface.
  • All partial-type definitions meant to be parts of the same type must be defined in the same assembly and the same module (.exe or .dll file). Partial definitions cannot span multiple modules.
  • The class name and generic-type parameters must match on all partial-type definitions. Generic types can be partial. Each partial declaration must use the same parameter names in the same order.
  • The following keywords on a partial-type definition are optional, but if present on one partial-type definition, cannot conflict with the keywords specified on another partial definition for the same type:
    • public
    • private
    • protected
    • internal
    • abstract
    • sealed
    • base class
    • new modifier (nested parts)
    • generic constraints

Sunday, December 19, 2010

Self-Tracking Entities - Introduction

In an Entity Framework application, an object context is responsible for tracking changes in the entities in an object graph.
However, in N-tier scenarios, the object context might not be available on the tier that modifies the entities. Starting with the .NET Framework version 4, self-tracking entities can help you track changes in any tier.
Starting with Microsoft Visual Studio 2010, the ADO.NET Self-Tracking Entity Generator template generates self-tracking entities.
template item generates two .tt (text template) files:
  • <model name>.tt and
  • <model name>.Context.tt.
The <model name>.tt file generates
  • the entity types and
  • a helper class that contains the change-tracking logic that is used by self-tracking entities and
  • the extension methods that allow setting state on self-tracking entities.
The <model name>.Context.tt file generates
  • a typed ObjectContext and
  • an extension class that contains ApplyChanges methods for the ObjectContext and ObjectSet classes

Wednesday, December 15, 2010

Different between Events and Delegates

Main Differences
  1. events can be used in an interface
  2. events can be only fired from the class in which it is declared
The below article explains about the difference between Events and Delegates.
http://blog.monstuff.com/archives/000040.html

TableSplitting with Entity Framework

Table Splitting is design of mapping Multiple Conceptual Entities to Single Storage Table.

Check this link for more info

http://www.deveducate.com/blog/post/2010/12/14/Entity-Framework-Modeling-Table-Splitting.aspx

Tuesday, December 14, 2010

MetadataException: Unable to load the specified metadata resource

I faced an issue while trying to open an EntityConnneciton with the following message.

MetadataException: Unable to load the specified metadata resource.

The issue is the i had the Entity Model in a seperate assembly and the assembly doesn't load itsef if you try to connect to it using EntityConnection classes. If you use the object context class generated by the model then we don't face this issue.