Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.0] Treat Views as Entities? #741

Open
cilerler opened this issue Nov 26, 2023 · 2 comments
Open

[2.0] Treat Views as Entities? #741

cilerler opened this issue Nov 26, 2023 · 2 comments
Labels
Milestone

Comments

@cilerler
Copy link
Contributor

cilerler commented Nov 26, 2023

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."
@robertmclaws robertmclaws added this to the 2.0 milestone Dec 5, 2023
@robertmclaws robertmclaws changed the title Support Views [2.0] Treat Views as Entities? Dec 5, 2023
@robertmclaws
Copy link
Collaborator

Investigate whether or not we can support Views as if they are entities, how we would determine if a View has CRUD support, and what to do if the entities are keyless, as everything in Restier usually requires a key.

@bytefish
Copy link

@robertmclaws Wouldn’t it be a good idea to map the View to an OData Function, and using a ComplexType as a return value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

3 participants