Skip to content

emrekara37/EfCore.JsonColumn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EfCore.JsonColumn

Nuget => https://www.nuget.org/packages/EfCore.JsonColumn/

Usage Example

 
 
 /* Your Entity */

 public class SampleEntity
    {
        public int Id { get; set; }
        public string Name { get; set; }
        
        // Add attribute
        [ToJsonColumn]
        public SampleJsonColumn JsonColumn { get; set; }
    }

 
    public class SampleJsonColumn
    {
        public string Description { get; set; }
        public DateTime Date { get; set; }
    }

public class SampleContext : DbContext
    {
        public DbSet<SampleEntity> SampleEntities { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            // Call the  extension method 
            modelBuilder.ApplyJsonColumns();

            base.OnModelCreating(modelBuilder);
        }
    }

Add-Migration

migrationBuilder.CreateTable(
                name: "SampleEntities",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    // Type is string 
                    JsonColumn = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SampleEntities", x => x.Id);
                });

Screenshot_9

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages