| Reference |
Timestamp |
Code |
| Install InterSystems IRIS Entity Framework Core Provider dependency |
2:30 |
Begin code:PM> Install-Package InterSystems.EntityFrameworkCore.Iris End code. |
| Install Entity Framework Core Tools dependency |
2:50 |
Begin code:PM> Install-Package MicrosoftEntityFrameworkCore.Tools -Version 8.0.16 End code. |
| Blog class, Blog.cs |
4:17 |
Begin code:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimpleEFDemo.Models
{
internal class Blog
{
public int BlogId { get; set; }
public string Name { get; set; }
public List<Post> Posts { get; set; } = new();
}
}End code. |
| Post class, Post.cs |
4:32 |
Begin code:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimpleEFDemo.Models
{
internal class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
} End code. |
| Context class, BloggingContext.cs |
6:23 |
Begin code:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace SimpleEFDemo
{
internal class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
public BloggingContext() { }
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
options.UseIris("Server = localhost; Port = 51776; Namespace = Demo; User ID = _SYSTEM; Password = SYS");
}
}
}End code. |
| Create migration classes for code-first workflow |
7:05 |
Begin code:PM> Add-Migration InitialCreate End code. |
| Implement migrations in InterSystems IRIS |
8:09 |
Begin code:PM> UpdateDatabase End code. |
| Blog program class, Program.cs |
11:10 |
Begin code:using SimpleEFDemo;
using SimpleEFDemo.Models;
using var db = new BloggingContext();
// Read by creating LINQ queries that will query the relevant tables in IRIS
Console.WriteLine("Querying for a blog");
var blog = db.Blogs
.OrderBy(b => b.BlogID)
.First();
// Update by modifying existing blog instance then saving the changes
blog.Name = "My Updated Blog";
blog.Posts.Add(
new Post
{
Title = "Hello World",
Content = "I wrote an app using EF Core!"
});
db.SaveChanges(); End code. |
| Create table statement |
14:27 |
Begin code:CREATE TABLE Coupon (Id INT, Description VARCHAR(1023), Expiration DATETIME); End code. |
| Insert statement |
14:45 |
Begin code:INSERT INTO Coupon (Id, Description, Expiration) VALUES (1, 'Buy 1 get 1 free', '2025-01-01'); End code. |
| Command to generate models from an InterSystems IRIS database |
18:00 |
Begin code:Scaffold-DbContext "Server = localhost; Port = 51776; Namespace = Promotions; User ID = _SYSTEM; Password = SYS;" InterSystems.EntityFrameworkCore.Iris -OutputDir Models End code. |
| Coupon program class, Program.cs |
19:25 |
Begin code:using SimpleEFDatabaseFirst.Models;
using Microsoft.EntityFrameworkCore;
var context = new PromotionsContext();
var coupons = context.Coupons.AsNoTracking().ToList();
foreach (var coupon in coupons)
{
Console.WriteLine($"{coupon.Id}: '{coupon.Description}' expires {coupon.Expiration}");
} End code. |