Thursday, 15 April 2010

orm - Entity Framework: Doing JOINs without having to creating Entities -


Just starting with the unit framework (code first), and let me say that when I load it Problems are happening in SQL data which is quite complex. For example, suppose I have the following tables which stores which animals are in the category of animals and animals in the world. Name: string field id: integer - back refers to field table animal id integer AnimalCategoryId integer - refers back to AnimalCategory

Suppose that I want to create a query with the unit framework The most simple thing is that a specific area will load all the animals, using LINQ to create 3 unit areas, animal category, and animal and to load data.

But we say that I am not interested in loading any AnimalCategory information and only define the entity class to represent AnimalCategory so that I can JOIN. How can I do this with the unit framework? Even with its many mapping functions I do not even think that this is possible.

In non-entity framework solutions, it's easy using INNER Jones in SP or Inline SQL, so what are my options in the unit framework? Will I pollute my data model with these useless tables, so that I can include one?

This is a matter of choice I think EF with multiple junctions of transparent junction tables Selects to support, i.e. where affiliate tables are only two foreign key in the affiliates.

And I can imagine why.

To get started in several organizations, the junction table is nothing: a junction, a union. However, in a series of multiple-to-many (or several-to-one) associations, for any table that contains it, it will be extraordinary to be just a union in your example ...

  Animal → AnimalCategory → Area  

... AnimalCategory will only enter a primary key ( Id ) And a foreign key ( RegionId ). It would be useless though: Animal can also be a regional there is no reason to support a data model that does not make sense.

What you are doing later, this is a model in which the table takes the information ( AnimalCategory.Name ), but where you have it in the form of a transparent junction table You want to map, because the model of a particular class does not need this information.

Your attention is on reading the data but EF has to support all CRUD functions. Here the problem will be how to handle the inserts? Assume that name is a required field.

Another problem would be that a statement like ...

  area. Unimple Add (animal);  

... two things can mean:

  1. a animal and new Animal category , later references the area .
  2. An existing AnimalCategory - without being able to choose any one

EF does not want to select for some default behavior, you have to make your choice, so you can not do without access to AnimalCategory .


No comments:

Post a Comment