Page 1 of 1

Looking for C# EF example using JSON

Posted: Mon 02 Mar 2015 15:34
by bobcardenas
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.

Re: Looking for C# EF example using JSON

Posted: Tue 03 Mar 2015 12:22
by MariiaI
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.