OData / OData/RESTier

[2.0] Treat Views as Entities?

Open
#741 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
C#
Stars
481
Forks
136
PR merge metrics
No merged PRs in 30d

Description

As a user, I would like to be able to expose my views via RESTier. This way, RESTier will serve as a single service to expose the database.

[!TIP]
While OData supports keyless views, RESTier currently does not.

[!NOTE]
I created this as a separate issue with a lean example, so it can serve as a placeholder for an important feature.
Even though there is a workaround in the original post, it defeats the purpose of using RESTier when it comes to views.

Assemblies affected

RESTier 1.1.0-rc.2.20231126.0

Reproduce steps
  1. Add a new file CurrentProductList.cs with the snippet below to here

    using Microsoft.EntityFrameworkCore;
    
    using System.ComponentModel.DataAnnotations.Schema;
    
    namespace Microsoft.Restier.Samples.Northwind.AspNetCore.Data
    {
        [Keyless]
        public class CurrentProductList
        {
            [Column("ProductID")]
            public int ProductId { get; set; }
            public string ProductName { get; set; }
        }
    }
    
  2. Add the snippet below here

    public virtual DbSet<CurrentProductList> CurrentProductList { get; set; }
    
  3. Add the snippet below here

    modelBuilder.Entity<CurrentProductList>(entity =>
    {
        entity.ToView("CurrentProductListt");
        entity.Property(e => e.ProductId);
        entity.Property(e => e.ProductName);
    });
    
Expected result

The views should be added without errors.

Actual result

An error occurs at here as detailed below.

@$"The entity '{pair.Key}' does not have a key specified. Entities tagged with the [Keyless] attribute 
(or otherwise do not have a key specified) are not supported in either OData or Restier. 
Please map the object as a ComplexType and implement as an [UnboundOperation] on your API instead."

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at src/Microsoft.Restier.AspNet.Shared/Model/RestierWebApiModelBuilder.cs around line 83, then review the sample model in Data/CurrentProductList.cs and Data/NorthwindContext.cs. Reproduce the keyless view setup described in the issue and determine the required model behavior. Done means the view can be added and exposed through RESTier without the current key-related error.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.