EntityFramework6.Npgsql icon indicating copy to clipboard operation
EntityFramework6.Npgsql copied to clipboard

Forced to use DataAnnotations, where it used to work without on SQL Server

Open a-einstein opened this issue 6 years ago • 2 comments

I am new to this, so I might not see the whole picture.

I had a working service with EntityFramework 6 on SQL Server. It was created database first, generating a edmx file. In there all the keys are clearly marked. There are also generated data classes, which do not have those markings by themselves.

As an experiment I am converting my application to be used on top of Postgres.

  • I have partially converted the database using DBConvert, using the same schema name 'Production' as in the original, which is AdventureWorks2014.
  • I added packages EntityFramework6.Npgsql, plus implicitly Npgsql and Tasks.Extensions.

I have been struggling with quite some problems. Some of them seem to be resolved by using DataAnnotations. It took me a long time to find out. And I was surprised, as it used to work without, and it even seems old fashioned belonging to older versions of EntityFramework. Besides, it is in generated code, so that may give problems in the future.

I ended up with classes like this (brief). All the attributes are added, and were necessary because of error messages about keys, column orders, and the dbo schema.

[Table("ProductProductPhoto", Schema = "Production")]
public partial class ProductProductPhoto
{
    [Key]
    [Column(Order = 0)]
    public int ProductID { get; set; }

    ...
 }

So my question is: is this supposed to be necessary, or is this a flaw in Npgsql?

a-einstein avatar Feb 06 '18 13:02 a-einstein