Entity Framework and Cosmos DB

Job ID: 37520381

Budget: ₹1,500 – ₹12,500 INR

Using .Net 8, use Entity Framework Core, DbContext, to write this User entity with at least 2 Roles and read it back out of the database. The challenge is EF Core doesn’t natively work with ImmutableList and prefers any other type of list. But making sure the entity is fully immutable (cannot change at all after initializing) and using ImmutableList is the requirement. There are many examples of how to do this, but I haven’t gotten them working.



Here is the entity:



using System;

using System.Collections.Immutable;



public sealed record Role {

public Guid Id { get; init; }

public string Name { get; init; }

}

public sealed record User {

public Guid Id { get; init; }

public string Name { get; init; }

public ImmutableList<Role> roles { get; init; }

}



var role1 = new Role { Id = Guid.NewGuid(), Name = "Admin" };

var role2 = new Role { Id = Guid.NewGuid(), Nam = "User" };

var user = new User {

Id = Guid.NewGuid(),

Name = "John Doe",

Roles = ImmutableList.Create(role1, role2)

};
Related categories: .NET C# Programming ASP.NET Microsoft SQL Server