Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1793

New Post: Model-First and Database-First should create entity constructors with parameters

$
0
0
For an entity reflecting a database table with non-nullable columns, it doesn't make sense to provide a parameterless entity constructor. If not all of the non-nullable properties get set, then the entity will positively not commit to the database.

Currently, creating a valid entity results in a hide-and-seek -or better- try-and-error game of finding and setting all non-nullable properties in a second step. This is particularly true for string properties.

So, I suggest to have Database-first and Model-first create a constructor overload with parameters for each non-nullable property. This way the programmer is able to tell which properties need to be set right from the beginning.

E. g.
CREATE TABLE Tests
  (ID INT PRIMARY KEY IDENTITY
  ,Name NOT NULL UNIQUE CHECK (LEN(Name) > 0)
  )
Should result in:
public partial class TestEntity()
{
  public TestEntity() {}

  public TestEntity(id int, name string)
  {
    ID = id;
    Name = name;
  }
}

Viewing all articles
Browse latest Browse all 1793

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>