Closed cilerler closed 2 years ago
This was due to some issues with how EFCore was originally plumbed. I believe we have this fixed in the latest version. Can you please test with RC8 and see if it is still a problem?
Thanks!
Tested with RC8, and still has the same issue, can't even get $metadata
<PackageReference Include="Microsoft.Restier.EntityFrameworkCore" Version="1.0.0-rc8.20220714.1" />
Can you get an updated callstack and error line, please? Line 90 is blank in the current codebase.
Thanks!
This is the place that throws the error due to null
value
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.7">
public virtual DbSet<SalesByCategory> SalesByCategory { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//...
modelBuilder.Entity<SalesByCategory>(entity =>
{
entity.ToView("Sales By Category");
entity.Property(e => e.CategoryId).HasColumnName("CategoryID");
entity.Property(e => e.CategoryName)
.IsRequired()
.HasMaxLength(15);
entity.Property(e => e.ProductName);
entity.Property(e => e.ProductSales);
});
//...
}
using Microsoft.EntityFrameworkCore;
#nullable disable
namespace Microsoft.Restier.Samples.Northwind.AspNetCore
{
[Keyless]
public partial class SalesByCategory
{
public int CategoryId { get; set; }
public string CategoryName { get; set; }
public string ProductName { get; set; }
public decimal ProductSales { get; set; }
}
}
I don't know if supporting Views this way is going to be possible. I unblocked the NullReferenceException
you were getting, but OData's core libraries now throw an InvalidOperationException
, that Entities must have keys. This is expected behavior.
You would have to manually override the ODataConventionModelBuilder
and map SalesByCategory
as a ComplexType
instead, and then create a method on the NorthwindApi
that returns SalesbyCategory
based on your query.
For deeper Views support, I think you would need to open an issue in the OData core repo and ask them to support keyless entities.
We will include the NullReferenceException fix in the RTM build. Sorry I couldn't unblock this one for you.
I updated the codebase to have a unit test for this issue, and I have also caught the scenario and thrown a more informative exception. You can see the changes in this commit: https://github.com/OData/RESTier/commit/4b15400dbe9d3177c209bf0aea7fce193dfe54c6
Hi guys, maybe someone here can help me with this issue, I do have some keyless views, and I get the error as @robertmclaws referenced in commit, but I would like to kick out that view from my RESTier controller, I don't need that keyless data. I would like to keep using those views in other parts of my app.
Is there some clean and fast way to get rid of all Keyless objects coming from my EF project to RESTier?
Having a
Keyless
attribute (which is a common scenario for Views) causes aSystem.NullReferenceException
on https://github.com/OData/RESTier/blob/1a6182ca41ae762d2071200b4cfa589bb23359ed/src/Microsoft.Restier.EntityFramework.Shared/Model/EFModelBuilder.cs#L90Error Message
Assemblies affected
Reproduce steps
Create a table on the database.
Add it to DbContext
Update the Northwind