'Relationships in Entity Framework with users from AzureAD

I'm relatively new to Microsoft solutions and I need your guidance. I'm quite certain the answer exist somewhere, but I lack key words for my searches.

My stack is as follows: .NET Core 6, Entity Framework, Azure AD.

Ideally, I wouldn't need to store user's information in my DB. Everything should come from Azure AD. Authentication is already working, and I'm able to retrieve my current user in my controllers and services.

My goal is to add some relationships between my Azure AD users and some of my entities.

For example, let's say I'm doing a collaborative Todo list and I want my users to be able to cancel tasks. So I have an entity named Task, and in it, a column named CanceledBy.

On cancellation, in my TaskService, I want to do something like that:

var task = dbContext.tasks.find(taskId);
task.CancelledBy = User;

"User" is the current user. In a perfect world, it works like that, out of the box. Behind the magic, the user OID would be stored, and the user would be automatically resolved through GraphAPI (or something else?) when needed.

I'm guessing there may be a type that could help me in my entity Task? Like:

public class Task 
{
    ...
    AzureADUser CancelledBy {get;set;}
}

And some configuration to add to my Startup.cs.

Or am I completely wrong? Am I doomed to implement myself a service to retrieve my users through GraphAPI with their OID?

In that case my Task would look more like

public class Task 
{
    ...
    string? CancelledByOID {get;set;}
    [NotMapped]
    User? CancelledBy {get;set;}
}

And I'd have to map my users manually in my services every time I need them?

I'm simply looking for direction here. What are key words I could use to help my search? I tried stuff like "Relathionship with Azure AD User in Entity Framework", or "GraphAPI and Entity Framework" without success.

Thank you!

EDIT : After more searches, I think I want to do LinQ on OData connected to Entity Framework and Graph API. I hope it makes sense.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source