C# - .NET- Cross partition query is required but disabled when I Get

.net azure-cosmosdb azure-cosmosdb-sqlapi c# entity-framework-core

Question

I'm building a web API with .net core and the CosmosDb SQL API. My post method works, but when I try to get data from the database I get an error "Cross partition query is required but disabled".

I am using the entity framework core for cosmosdb sql and I found a "solution" using feedoptions to enable Cross partition, but I am not using a query the same way they did in the "solution" I found. So I have no idea where to insert the feedoptions, or if that is even the right solution for me.

Click here for the "solution" I found.

Get method in SensorController.cs:

    [HttpGet]
    public ActionResult<IEnumerable<Sensor>> Get()

    {

        var bookmarks = _sensorContext.Sensors.ToList();

        return Ok(bookmarks);

    }

SensorContext.cs:

    public SensorContext(DbContextOptions options) : base(options)
    {
    }


    public DbSet<Sensor> Sensors { get; set; }
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Sensor>();
        var sensors = modelBuilder.Entity<Sensor>().Metadata;
        sensors.CosmosSql().CollectionName = "Sensors";
    }

I expected to get a list of all the sensors in my database but I just get the Cross origin error instead.

1
0
1/23/2019 9:19:05 AM

Popular Answer

Seems that you're using an old version of the CosmosDB Entity Framework. Make sure to download the latest NuGet package, which is currently:

dotnet add package Microsoft.EntityFrameworkCore.Cosmos -v 3.0.0-preview.18572.1

Afterwards, you may try out following walkthrough: Announcing Entity Framework Core 2.2 Preview 3

I managed to create and retrieve documents by executing the steps shown in the link above.

2
1/23/2019 1:07:46 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow