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.