EF core for nvarchar support

I have an existing EF code project that created a database with all nvarchar columns in the database. Now I am running another project on the same database for statistical purpose. However, this new project uses the EF core as a reference to the same database. When I tried to start a new project it gives me the following error.

"The data type 'VARCHAR' is not supported in this form. Either specify the length explicitly in the type name, such as" VARCHAR (16) ", or remove the data type and use APIs such as HasMaxLength to allow EF to select the data type."

Now, since I already have production data in the database, so I want to make minimal impact on column types, but still want to use EC core in my new project. I have so many nvarchar columns, so setting up the configuration on a separate table is hard work. Can anyone point me in the right direction?

+3


source to share


2 answers


This seems to be an issue with the 2.0 EntityFrameworkCore release: https://github.com/aspnet/EntityFrameworkCore/issues/9188

Let's assume it's fixed in 2.1, so you can wait until then.



Otherwise, they suggest manually installing it like this:

            entity.Property(e => e.Comments)
                .HasColumnName("Comments")
                .HasColumnType("nvarchar(4000)"); // <- Add this

      

+1


source


I am using data annotation and it still works. [Column(TypeName = "varchar(50)")]



0


source







All Articles