I am having trouble to insert an object using a POST request. DictAreas entity are associated with a one-to-many DictCities entity. When I submit a request, it sends me a response with this exception and a 500 status code, but when I check the DB, I see that the value for DictAreas has been added. Is it possible to somehow disable the hierarchical data insertion mode or solve this problem differently?
I am using models created by Linq2Db with T4 templates (MS SQL Server). We are also trying to make one controller for all entities, GET and PATCH requests works fine, but there are problems with this exception.
Exception
System.InvalidOperationException: Not found table for clr type ExampleProject.DB.DictCity
at OdataToEntity.Linq2Db.OeLinq2DbDataContext.UpdateIdentities(OeLinq2DbTable table, Int32 lastIndex)
at OdataToEntity.Linq2Db.OeLinq2DbDataContext.SaveChanges(DataConnection dataConnection)
at OdataToEntity.Linq2Db.OeLinq2DbDataAdapter`1.SaveChangesAsync(Object dataContext, CancellationToken cancellationToken)
at OdataToEntity.AspNetCore.OeBatchFilterAttributeAttribute.OnActionExecuted(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location ---
Code
Models
using System;
using System.Collections.Generic;
using LinqToDB;
using LinqToDB.Data;
using LinqToDB.Mapping;
using OdataToEntity.Linq2Db;
namespace ExampleProject.DB
{
public partial class ExampleDB : DataConnection, IOeLinq2DbDataContext
{
OeLinq2DbDataContext IOeLinq2DbDataContext.DataContext
{
get;
set;
}
public ITable<DictArea> DictAreas { get { return this.GetTable<DictArea>(); } }
public ITable<DictCity> DictCities { get { return this.GetTable<DictCity>(); } }
}
[Table(Schema = "dbo", Name = "DictArea")]
public partial class DictArea
{
[PrimaryKey, Identity] public int AreaID { get; set; } // int
[Column, NotNull] public string Name { get; set; } // nvarchar(50)
[Column, Nullable] public string Code { get; set; } // nvarchar(10)
[Association(ThisKey = "AreaID", OtherKey = "AreaID", CanBeNull = true, Relationship = LinqToDB.Mapping.Relationship.OneToMany, IsBackReference = true)]
public IEnumerable<DictCity> DictCities { get; set; }
}
[Table(Schema = "dbo", Name = "DictCities")]
public partial class DictCity
{
[PrimaryKey, Identity] public int CitiesID { get; set; } // int
[Column, NotNull] public string Name { get; set; } // nvarchar(50)
[Column, NotNull] public int AreaID { get; set; } // int
[Column, Nullable] public bool? IsVillage { get; set; } // bit
[Column, NotNull] public bool IsActive { get; set; } // bit
[Column, Nullable] public string Code { get; set; } // nvarchar(10)
[Column, NotNull] public bool IsDefault { get; set; } // bit
[Column, Nullable] public int? LocationID { get; set; } // int
[Association(ThisKey = "AreaID", OtherKey = "AreaID", CanBeNull = false, Relationship = LinqToDB.Mapping.Relationship.ManyToOne, KeyName = "FK_DictCities_DictArea", BackReferenceName = "DictCities")]
public DictArea Area { get; set; }
}
}
Controller
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.OData.Edm;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using OdataToEntity.Query;
using OdataToEntity.AspNetCore;
using ExampleProject.DB;
namespace ExampleProject.Controllers
{
[Route("api/v1/[controller]")]
public sealed class DictAreasController
{
private readonly IHttpContextAccessor _httpContextAccessor;
public DictAreasController(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
[HttpGet]
public async Task Get()
{
var edmModel = (IEdmModel)_httpContextAccessor.HttpContext.RequestServices.GetService(typeof(IEdmModel));
OeModelBoundProvider modelBoundProvider = OeAspHelper.CreateModelBoundProvider(edmModel, 50, false);
await OeAspQueryParser.Get(_httpContextAccessor.HttpContext, modelBoundProvider).ConfigureAwait(false);
}
[HttpPost]
public void Post(OeDataContext dataContext, DictArea obj)
{
dataContext.Update(obj);
}
[HttpPatch]
public void Patch(OeDataContext dataContext, IDictionary<String, Object> obj)
{
dataContext.Update(obj);
}
}
}
Description
I am having trouble to insert an object using a POST request. DictAreas entity are associated with a one-to-many DictCities entity. When I submit a request, it sends me a response with this exception and a 500 status code, but when I check the DB, I see that the value for DictAreas has been added. Is it possible to somehow disable the hierarchical data insertion mode or solve this problem differently?
I am using models created by Linq2Db with T4 templates (MS SQL Server). We are also trying to make one controller for all entities, GET and PATCH requests works fine, but there are problems with this exception.
Exception
Code
Models
Controller