Moses' Blog

Living {.net} lifestyle

Muhammad Mosa

Moses' profile picture
Logo
Software Engineer.
MCT, MCSD.NET,
MCTS: .Net 2.0 Web, Windows, Distributed Applications
MCTS: .Net 3.5 WF Application Development
MCTS: WSS 3.0, MOSS 2007 Configuration & App Dev
MCPD: Enterprise Application Developer

Send mail My Live Space Moses on Facebook Twitter Moses on Technorati

Sponsors



Calendar

<<  November 2008  >>
MoTuWeThFrSaSu
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

View posts in large calendar

Recent Comments

Comment RSS

Community Credit

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Inheritance and Associations with Entity Framework Part 3

On part 1 and part 2 I explored how to apply 2 different inheritance models (TPH & TPT) in Entity Framework. In this part I'm going to demonstrate associations between 2 base entities. And how to filter end properties to return specific type (sub entity). Download the sample.

Review Association Ends:

In previous part when I added department tables to the entity model diagram, an associations between Person and Department entities was automatically defined. This relation actually demonstrate the relation between Administrator and Department. It is one-to-many relationship where one person can be administrator of one or many departments.

A collection of Departments is created on Person table and therefor it is inherited on all sub entities! But this make no sense, as a student or instructor has nothing to do with this collection. Beside on the other end at Department a property of type Person is created -I renamed it to Administrator-, while this shouldn't be just any Person, this Person must be of type Administrator.

A few modification should take place in here. The existing association should be deleted and the association ends should be define between Administrator Entity and Department Entity. To do that follow the following steps:

More...

Posted: Oct 01 2008, 07:00 by mosessaur | Comments (2) RSS comment feed |
  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Entity Framework
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us
Inheritance and Associations with Entity Framework Part 2

In the previous part I discussed Table-per-Hierarchy Inheritance, in this part I'll go through Table-per-Type Inheritance model. There is a video demonstrating this model if you wish to watch. Here I'll update my previous sample with new entities that demonstrate the Table-per-Type Inheritance model. For the differences between 2 models and definitions return to 1st part. The updated sample can be downloaded from here.

How to define a model with Table-per-Type Inheritance:

At the beginning I'll explore the database design for this subject, and explain why Table-per-Type must be used to model the inheritance:

More...

Posted: Sep 29 2008, 21:55 by mosessaur | Comments (2) RSS comment feed |
  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Entity Framework
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us
Inheritance and Associations with Entity Framework Part 1

In this multi parts series I'll explore how to build inheritance with Entity Framework showing 2 different approaches of inheritance in Entity Framework. Beside that I'll show how to build simple association between 2 entities and show how to provide custom code to retrieve other parts of the relation when inheritance is applied.

My plan not to exceed 3 parts as the subject is not that huge, it is just the demonstration with screen shots that will make the post large that is why I divided it to multi part. I am not good at screen casts beside I don't have a software license to produce one.

Inheritance Types in Entity Framework:

There are 2 models of Inheritance in Entity Framework and they both actually depends on the database design:

  • Table-per-Hierarchy Inheritance: One table in storage to maintain data for all the types in an inheritance hierarchy. So basically you have one table in database, but different types in your Entity Model that inherits from a base class and all mapped to that table. This post will focus on this type of Inheritance.
  • Table-per-Type Inheritance: Separate table in storage to maintain data for each type in the inheritance hierarchy. That means you might have several tables with one-to-one relationships. Each table is mapped to single Entity in the model. But there is a base Entity that is mapped to the very base table. This is going to be the subject of my next part of this short series. Till then you can watch this video about it.

About the Sample:

The sample I am going to demonstrate here with screen shots is taken from MSDN sample in the links specified above. I found them much clear and easy to demonstrate beside I wasn't able to come out with much simpler sample idea.

More...

Posted: Sep 24 2008, 16:06 by mosessaur | Comments (3) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Entity Framework
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us
LINQ to Entities, Workarounds on what is not supported

In my previous post I talked about what is not supported in LINQ to Entities and made a simple comparison with LINQ to SQL show that these unsupported things works fine in LINQ to SQL.

Here I am going to provide workarounds these things. First one will be wrapping the entities with Business Classes. And the second way will be using client evaluation which is converting to work with LINQ to Object. Before you go further, I recommend that you read my previous post to save your time.

More...

Posted: Aug 31 2008, 02:21 by mosessaur | Comments (8) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Entity Framework | LINQ
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us
LINQ to Entities, what is not supported?

Recently and after .Net 3.5 SP1 & Visual Studio.Net 2008 SP1 released, I started to play with LINQ to Entities. Really Entity Framework is interesting. Maybe not the best ORM tool, but still it is interesting and easy to use plus it is all one IDE at the end.

At the same time I was watching screen-casts made by Rob Conery about Building MVC Storefront along with TDD. In fact he was using LINQ to SQL. And I liked his coding techniques presented in his sample application and screen-casts.

I decided to play around with LINQ to Entities with MVC. Here I am going to talk about my adventures with LINQ to Entities, and really it is completely different from working with LINQ to SQL.

My recommendation for every developer is to start by reading Supported and Unsupported Methods (LINQ to Entities). Yes it will save you sometime. Do You know LINQ to SQL? Then you are familiar with LINQ. But you need to know what there and what is not there in LINQ to Entities. This even Might help you to build a wish list for LINQ to Entities also ;O).

Here I'm going to use some code samples presented in MVC Storefront and show some of the techniques that will not work with LINQ to Entities. And I will compare code with LINQ to SQL. In some other post, I'm going to present some other workarounds provided by ADO.NET Team when I asked them about the issues I have with LINQ to Entities. Also I'll present my own workarounds. And I'll compare the Generate SQL statements. I am not query optimizer, so I will not say what is the best choice. But you can help me in that.
More...

Posted: Aug 24 2008, 07:00 by mosessaur | Comments (10) RSS comment feed |
  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: LINQ | Entity Framework
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us