Entity Framework question

Entity Framework question

Postby JoeRuspante » Mon 05 Mar 2012 08:24

Sorry for the bad subject, but I didn't know how to summarize the questions I need to do.

1) Model First relationship

When I have a relationship between two classes in the Model First scenario, the code generated is something like that:

Code: Select all

public Collection ClassBs
{
   get
   {
      return _classbCollection;
   }
   set
   {
      _classbCollection = value;
   }
}
private Collection _classbCollection;



Is it possible to change int in:


Code: Select all

public Collection ClassBs
{
   get
   {
      if (_classbCollection == null)
      {
          _classbCollection = new Collection();
      }
      return _classbCollection;
   }
   set
   {
      _classbCollection = value;
   }
}
private Collection _classbCollection;



In the first scenario, I always have to check if the relationship is null or I will have a "NullReferenceException" at runtime.
In the second scenario, no exception but simply no results.


2) When do you think to have enum support on Model First/Code First? (if you know, of course)

3) When do you think to improve Code First for stored procedure support? (as before, if you know that)



Thank you in advance.
JoeRuspante
 
Posts: 54
Joined: Mon 05 Jul 2010 23:08

Postby Shalex » Mon 05 Mar 2012 15:51

How do you implement the Code-First model? If you are asking about stored procedures, you probably have a predefined database. But for some reason, you write your classes manually. In this case we recommend creating a model in the designer of Entity Developer: http://www.devart.com/blogs/dotconnect/index.php/entity-developer-ef-code-first-dbcontext-template.html. Just drag&drop the database objects from Database Explorer on the diagram, add the DbContext template, and generate a model.

If you do not need a fluent mapping, you can use stored procedures. For this, set template's FluentMapping to False. As a result, DbContext's methods are generated for all stored procedures which are added to the model.
Shalex
Devart Team
 
Posts: 7530
Joined: Thu 14 Aug 2008 12:44

Postby JoeRuspante » Mon 05 Mar 2012 16:43

No, we don't have any DB right now. But we doesn't want to start a new project with a limitation like that.

So, if you think to have the stored procedure support in the end of the year, we can think to start using Code First also if it doesn't support SP yet.

About Model First (I saw it in another post), there is a think that we don't know how to do with it.

We have our "core" project that we'd like to define the class we will user.
Then have another project (DAL) that maps that classes in the DB.
In addition to it, another project (BIZ) that will have the business logic.

Finally one (or more) project with end user interface (UI).


If we use Code First, we can have 4 different projects in Visual Studio and change the DAL without any problem in the CORE or BIZ projects.

If we use Model First, CORE and DAL have to be in the same project (we draw the model in the same project where we design the mapping to the DB, so they are linked together).

Any idea about that?
JoeRuspante
 
Posts: 54
Joined: Mon 05 Jul 2010 23:08

Postby Shalex » Thu 15 Mar 2012 08:28

JoeRuspante wrote:So, if you think to have the stored procedure support in the end of the year, we can think to start using Code First also if it doesn't support SP yet.

Entity Framework Code First with fluent mapping itself doesn't support stored procedures: http://msdn.microsoft.com/en-us/library/gg696165%28v=VS.103%29.aspx. We recommend you to contact Microsoft about timeframe. The corresponding official Entity Framework UserVoice suggestion is here: http://data.uservoice.com/forums/72025-ado-net-entity-framework-ef-feature-suggestions/suggestions/1607971-code-first-support-for-stored-procedures.

JoeRuspante wrote:If we use Code First, we can have 4 different projects in Visual Studio and change the DAL without any problem in the CORE or BIZ projects.

If we use Model First, CORE and DAL have to be in the same project (we draw the model in the same project where we design the mapping to the DB, so they are linked together).

Any idea about that?

We do not have a deep experience in the development of different types of client applications with usage of Entity Framework. This is not our specialization. This question exceeds the goals of our support.
Shalex
Devart Team
 
Posts: 7530
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for Oracle