[2.0] Treat Views as Entities?
Nobody has claimed this yet.
- 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
-
Add a new file
CurrentProductList.cswith the snippet below to hereusing 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; } } } -
Add the snippet below here
public virtual DbSet<CurrentProductList> CurrentProductList { get; set; } -
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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