Looking for C# EF example using JSON

Looking for C# EF example using JSON

Postby bobcardenas » Mon 02 Mar 2015 15:34

We are building a new application and are new to using dotConnect from .Net to PostgreSQL. We have been unable to find good examples of using JSON fields in .Net applications with the EnitityFramework (EF) and migrations. Does dotConnect provide new class types that we can use when defining our class model? For example, if I want a field to store JSON data, what class type would I use in my model when I define the JSON field so that EF code-first migrations will generate the appropriate migration and that the field is created in database as JSON. I would also like to see examples of reading and writing EF models that have JSON fields.
bobcardenas
 
Posts: 2
Joined: Sun 01 Mar 2015 03:56

Re: Looking for C# EF example using JSON

Postby MariiaI » Tue 03 Mar 2015 12:22

You should use something like this:
Code: Select all
...
public virtual string JsonField
        {
            get;
            set;
        }
....
modelBuilder.Entity<TestJsonChild>()
                .Property(p => p.JsonField)
                    .HasColumnType("json");


We are sending you a small test project to the e-mail address you provided in your forum profile, please test it and notify us about the results.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to dotConnect for PostgreSQL