1

I have a large MySQL database mapped to POCOs using Entity Framework Data Annotations.

Most things work great, except one column in one table(or at least, I have not yet noticed any other similar problems).

mysql > describe _passwords;
+----------------+------------+------+-----+---------------------+----------------+
| Field          | Type       | Null | Key | Default             | Extra          |
+----------------+------------+------+-----+---------------------+----------------+
| id             | bigint(20) | NO   | PRI | NULL                | auto_increment |
| creation_date  | timestamp  | NO   |     | CURRENT_TIMESTAMP   |                |
| user_id        | bigint(20) | NO   | MUL | NULL                |                |
| password_hash  | char(64)   | NO   |     | NULL                |                |
| valid_end_date | timestamp  | NO   |     | 0000-00-00 00:00:00 |                |
+----------------+------------+------+-----+---------------------+----------------+

The password_hash column is mapped like this:

[Required]
[Index(IsUnique=true)]
[Column("password_hash")]
public String PasswordHash
{
    get;
    set;
} 

And yet when EF runs this query, it calls it PasswordHash, and naturally, fails.

When I try the same using Fluent API this works:

modelBuilder.Entity<Password>().Property(password => password.PasswordHash).HasColumnName("password_hash");

However, everything else is mapped with Data Annotations, and frankly, I like it this way. So would rather understand the root of this problem over moving this/all mappings to Fluent API

Svarog
  • 2,188
  • 15
  • 21

0 Answers0