How to map SQL Server text column with Entity Framework Core 2.0 Model property

entity-framework entity-framework-core sql

Question

I am using Entity Framework Core 2.0 and SQL Server 2016. I have a .cs class model that maps the SQL Server tables. I am able to insert long string in SQL Server text column, but I am not able to get that column with this model, it returns null with an error:

Object reference object reference not set to instance of object

Model property that holds data is type of string. Any ideas how to map a SQL Server text column with Entity Framework Core 2.0?

1
0
12/6/2017 1:44:34 PM

Accepted Answer

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Blog>(eb =>
    {
        eb.Property(b => b.Url).HasColumnType("ntext");
        eb.Property(b => b.ModernUrl).HasColumnType("nvarchar(MAX)");
    });
}

https://docs.microsoft.com/en-us/ef/core/modeling/relational/data-types

1
12/6/2017 5:23:58 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow