no dogma blog
no dogma blog
Blog Posts
Podcast
Web API Lambda Course
Polly Course
Photos
Contact
Support this Site
About
RSS
Light
Dark
Automatic
Entity Framework
Value cannot be null. Parameter name: constructor
Using Entity Framework I occasionally get the following error when reading from the database - `exceptionMessage=Value cannot be null. Parameter name: constructor` My Person class looked like this - 1 public class Person 2 { 3 public Person(string firstname, string lastname) 4 { 5 Firstname = firstname; 6 Lastname = lastname; 7 } 8 9 public Guid PersonId { get; set; } 10 public string Firstname { get; set; } 11 public string Lastname { get; set; } 12 public DateTime SomeDate { get; set; } 13 } There is no way for Entity Framework to know how to instantiate this object because there is no empty constructor.
Sep 17, 2016
#
Entity Framework
Entity Framework Core and calling a stored procedure
Download full source code here. I thought this would be easy, there is a method called ExecuteSqlCommand which takes the stored proc name and an array of parameters. I wanted to pass in two parameters and get one back, no problem, I’ve done this with ADO.
Jul 23, 2016
#
Entity Framework
Entity Framework, checking the connection string of your context
Sometimes when using Entity Framework I want to verify that I’m connected to the database I think I’m connected to. Here’s how to check in Entity Framework 5, Entity Framework 6 and Entity Framework Core 1 (EF 7)
Apr 11, 2016
#
Connection Strings
,
Entity Framework
Entity Framework with Proper Foreign Key Names
Full source code here. One of the very nice features of Entity Framework is the navigational properties. But it is easy to set them up in a less that optimal way.
Jun 12, 2015
#
Entity Framework
Entity Framework Migrations with an existing database
Introduction If you read my post on Entity Framework migrations, you might be saying, “that’s amazing, but that’s all very well for new projects, but we’ve got eighty tables in place already and that code first migration ship has sailed”.
May 11, 2015
#
Entity Framework
,
Migrations
Entity Framework non null foreign key migration
Full source code is provided. Overview This post gives a quick overview of how to use Entity Framework migrations and a detailed example of how to handle the addition of a new non null foreign keyed column to an existing table with data in it.
Apr 30, 2015
#
Database
,
Entity Framework
,
Migrations
Using JSON to store application preferences and configuration
Download full source code. Storing configuration preferences in the database is not a hard task. It usually involves storing the name of the preference, the value and the type in the database.
Apr 6, 2015
#
Entity Framework
,
JSON
Saving enums as strings with Entity Framework
In September 2018 I wrote a new post explaining how to store enums as ints or strings with Entity Framework Core. It is a nicer solution than the one presented here.
Nov 23, 2014
#
Entity Framework
,
Enum
Entity Framework lazy loading vs explicit loading and the generated SQL
Download the source code here. If you are using lazy loading with Entity Framework you should check that queries to the database are working as expected. A lazy load call to something like customer.
Aug 13, 2014
#
Entity Framework
,
Explicit loading
,
Lazy loading
Adding ROWGUIDCOL to Entity Framework Code First using migrations
To add add a ROWGUIDCOL to a unique identifier in a table using code first you have to use code migrations. Below is the snippet you need. I haven’t covered how to perform a migration because there are plenty of articles available.
Jul 29, 2014
#
Entity Framework
,
Migrations
«
»
Cite
×