Zeeshan Hirani

  • Stored Procedure returning entities and output parameter

    If you have a stored procedure that returns a collection of entities and also an output parameter, you must iterate through the resultset before the output value is available on the client. Accessing the output parameter value before looping through the result would give you null value. Let’s walk through an example to see how we can correctly access an output parameter value from a stored procedure.

  • Entities with complex Type properties cannot be returned from Stored Procedure

    Complex Types have been around since version 1 of Entity Framework. However the designer had no support for creating, modifying and returning entities with complex type. If you used complex type by editing the xml manually, you were not able to open the edmx file in design view. Although version 4 of Entity Framework made remarkable improvements in this area and working with complex type in designer is seamless, there is still a feature for complex type that did not make it into this release. If you have an entity that has a complex type property and you are returning that entity from a stored procedure, you will get a runtime InvalidOperationException. Although the designer would be happy to let you map this feature, at runtime you will see this exception.

  • Filtering Entities with foreign key value

    Entity Framework 4.0 supports two two types of association, foreign key association and independent association. Foreign key association which is new allows you to modify/filter an entity using either navigation property or foreign key column exposed on the entity.

  • Calling User Defined Database Function From LINQ

    Entity Framework 4.0 allows you to call a database function both in an esql query and linq to entities. However database function can only return scalar types. Future version would support table valued functions. To use a database function in a query, you have to perform the following steps.

  • Complex Type and POCO

    Change tracking in poco objects can be accomplished in two ways. If you mark your properties as virtual, EF will create a proxy object for your entity and any property changes will be notified to the ObjectStateManager immediately. However bare bone poco class has no mechanism to inform ObjectStateManager of changes occurring. When poco object is attached to the context, EF will take a snap shot of the current property values and when DetectChanges is called either explicitly or implicitly when SaveChanges occurs, EF will walk the object graph looking for changes that have occurred and modify the state of the object correctly in the state manager. This form of change tracking is called Snap Shot based change tracking where EF takes a snap shot of the original object and then a modified object to find the difference. Let’s look at example of a model consisting of Employee entity with Name property as complex type.

  • Entity Framework 4.0 class at Collins Community College

    Today I presented at Dallas C# user group. The audience was great with lots of interesting question. I met some new faces which i never saw. I saw substantial women participation in the group as compared to previous times which indicates that more women are in technology then you would think.  In fact my old friend Teresa was there too(thks for showing up girl!)

  • I finally became MVP

    I am excited to announce that i got awarded MVP title for the first time. Last year, i have spent good amount of time in the community by speaking in user groups, webcasts, writing book and helping developers on the Entity Framework Forum. With full time school and plus home work, it is tough to take time out for anything else. Hopefully i will continue to share my knowledge in the community and speak more often.

  • Entity Framework Videos

    Not too long ago, I gave two presentations on Entity Framework 4.0 covering new features like complex type, functions, stored procedures, POCO, Self Tracking Entity and some other features. Shawn was kind enough to record the videos for INETA.

  • Loading recursive queries

    Entity framework supports self referencing entity where an entity has a a reference to itself. A common example of that would be a category with subcategories. In the database you would typically see a category table with a ParentCategoryId column which represents the parent category of the current category. Figure below shows the Category table in the database.