Example

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using static EFCoreSql.SchoolContext;

namespace EFCoreSql
{
    public partial class CreateDatabase : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
        migrationBuilder.Sql("Some custom SQL statement");
        migrationBuilder.CreateTable(
            name: "Authors",
            columns: table => new
            {
                AuthorId = table.Column<int>(nullable: false),
                FirstName = table.Column<string>(nullable: true),
                LastName = table.Column<string>(nullable: true)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_Authors", x => x.AuthorId);
            });
        }
    }

    class SchoolContext : DbContext
    {
        public SchoolContext() : base()
        { }
        public class Student
        {
            [DatabaseGenerated(DatabaseGeneratedOption.Identity)]       
            public int StudentId { get; set; }
            public string Name { get; set; }
        }
        public class Course
        {
            public int CourseId { get; set; }
            public string CourseName { get; set; }
        }
        public DbSet<Student> Students { get; set; }
        public DbSet<Course> Courses { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseInformix("Database=efcoredb; server=Informix; User ID=user1; Password=xxxx; connectdatabase=no");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int rowCount = 1;
            
            using (var schoolContext = new SchoolContext())
            {
                schoolContext.ChangeTracker.LazyLoadingEnabled = false;

                bool _canCo = schoolContext.Database.CanConnect(); 
                if (_canCo == true)
                    Console.WriteLine("Informix database is good");
                else
                    Console.WriteLine("Not able to connect to Informix database!!");

                bool _Created = schoolContext.Database.EnsureCreated();
                if (_Created == false)
                    Console.WriteLine("Database exist in the Informix");
                else
                    Console.WriteLine("Database either got created or became the current database " +
                        "since connection string is using connectdatabase=no, and tables got " +
                        "created if it didn't exist in Informix!!");

                List<Student> stds = new List<Student>()
                {
                    new Student(){StudentId=1},
                    new Student(){StudentId=2},
                    new Student(){StudentId=3}
                };

                Console.WriteLine("Deleting all records from students table...");
                schoolContext.Students.RemoveRange(stds);
                schoolContext.SaveChanges();

                Console.WriteLine("Selecting record(s) from students table...");
                var _students = schoolContext.Students.FromSqlRaw("Select * from students;");
                var counter = _students.GetEnumerator();
                bool hasRow = counter.MoveNext();
                if (hasRow is false)
                    Console.WriteLine("No records found - Expected");
                else
                {
                    Console.WriteLine("Records found - NOT Expected!!");
                    rowCount = 1;
                    foreach (var row in _students)
                    {
                        Console.WriteLine("Row #" + rowCount + " = StudentId : " + row.StudentId
                            + ", Name : " + row.Name);
                        rowCount++;
                    }
                }

                Console.WriteLine("Inserting 3 records into students table...");
                // Insert records into Students table.
                var std1 = new Student() { StudentId = 1, Name = "Sheshnarayan" };
                var std2 = new Student() { StudentId = 2, Name = "Vardaan" };
                var std3 = new Student() { StudentId = 3, Name = "Samriddhi" };

                schoolContext.Students.AddRange(std1, std2, std3);
                schoolContext.SaveChanges();

                Console.WriteLine("Selecting record(s) from students table...");
                _students = schoolContext.Students.FromSqlRaw("Select * from students;");
                counter = _students.GetEnumerator();
                hasRow = counter.MoveNext();
                if (hasRow is false)
                    Console.WriteLine("No records found - NOT Expected!!");
                else
                {
                    Console.WriteLine("Records found - Expected");
                    rowCount = 1;
                    foreach (var row in _students)
                    {
                        Console.WriteLine("Row #" + rowCount + " = StudentId : " + row.StudentId + ", Name : " + row.Name);
                        rowCount++;
                    }
                }
            }

            using (var updateschoolContext = new SchoolContext())
            {
                updateschoolContext.ChangeTracker.LazyLoadingEnabled = false;

                bool _Created = updateschoolContext.Database.EnsureCreated();
                if (_Created == false)
                    Console.WriteLine("Database exist in the Informix");
                else
                    Console.WriteLine("Database either got created or became the " +
                        "current database since connection string is using " +
                        "connectdatabase=no, and tables got created if it didn't exist in Informix!!");

                Console.WriteLine("Updating Name column value to Monika of Students table " +
                    "where StudentID=1...");
                // Update records into Students table.
                var std4 = new Student() { StudentId = 1, Name = "Monika" };

                updateschoolContext.Students.Update(std4);
                updateschoolContext.SaveChanges();

                Console.WriteLine("Selecting just updated record to ensure its updated correctly from students table...");
                var _students = updateschoolContext.Students.FromSqlRaw("Select * from students where studentid=1;");
                var counter = _students.GetEnumerator();
                bool hasRow = counter.MoveNext();
                if (hasRow is false)
                    Console.WriteLine("No records found - NOT Expected!!");
                else
                {
                    Console.WriteLine("Records found - Expected");
                    rowCount = 1;
                    foreach (var row in _students)
                    {
                        Console.WriteLine("Row #" + rowCount + " = StudentId : " + row.StudentId + ", Name : " + row.Name);
                        rowCount++;
                    }
                }
            }
        }
    }
}