Build a Basic CRUD App with ASP.NET Core 3.0 and MongoDB

Build a Basic CRUD App with ASP.NET Core 3.0 and MongoDB

A quick introduction to ASP.NET Core with MongoDB as a data store.

ishant yadav

the startup file code
is missing


Hey Lee, great article. A question on how to proceed with routes…As shown above, the sub/user id can be obtained from

User.Claims.FirstOrDefault(c=>c.Type == ClaimTypes.NameIdentifier).Value;

My question is how would I set this up to make routes feel a bit more restful. For example, one of the canonical examples is the below. Of course, the authorId can obviously be obtained by accessing the claims from the ClaimsIdentity rather than passing it in the route. However it feels more restful-ish to me to pass it in the route.

public IQueryable<book> GetBooksByAuthor(int authorId)
return db.Books.Include(b => b.Author)
.Where(b => b.AuthorId == authorId)

How would you suggest it be architected so routes remained a bit more rest-ish in style. Even though it would be unnecessary, can the sub be sent in each request so it becomes part of the route? For example,

public IQueryable<book> GetBooksByAuthor(string sub)

Tadas Talaikis

Startup.cs(25,32): error CS0246: The type or namespace name ‘DatabaseSettings’ could not be found