1. Cami Lawson
  2. SnapObjects
  3. Thursday, 11 July 2019 13:42 PM UTC

I was working with the Create Web API tutorial and tried to add another call for another table other than Departments.  I created a Controller for Persons and all subsequent items, which would take the RetrieveOne for an int on the AdventureWorks2017 sql db for table Person.Person and use the BusinessEntityID similar to the DepartmentID.  Noticed that Department is a small int in the db and BusinessEntityID is just an int.  Shouldn't make much difference.  I'm getting the following errors and cannot for the of me understand what is wrong.  Just coming back to PB after being gone to the world of CF/SQL for 20yrs.  I have also included an image of my solution just in case that helps.

Error:

InvalidOperationException: Data type of mapped property on model is not compatiable, property: BusinessEntityID

  • SnapObjects.Data.DataModelBinding.BindModel(IList columnSchema, IPocoModelMeta modelMeta, ITypeMapper mapper)

  • SnapObjects.Data.DataModelBinder..ctor(IModelFactory factory, IList columnSchema, ITypeMapper typeMapper)

  • SnapObjects.Data.DataModelBinderFactory.GetBinder(IList columnSchema, ITypeMapper typeMapper, Type modelType)

  • SnapObjects.Data.AdoDbResultSet..ctor(IAdoDbDataVisitor dataVisitor, ITypeMapper typeMapper, Type modelType)

  • PowerBuilder.Data.AdoDbDataSource.Retrieve(object[] arguments)

  • PowerBuilder.Data.DataStore.Retrieve(object[] arguments)

  • WebAPI1.Services.PersonService.RetrieveOne(int id) in PersonService.cs

    1. }
    2. public IDataStore RetrieveOne(int id)
    3. {
    4. var dataStore1 = new DataStore("d_person", _dataContext);
    1. dataStore1.Retrieve(id);
    1. return dataStore1;
    2. }
    3. public int Create(D_Person person)
    4. {
  • WebAPI1.Controllers.PersonsController.RetrieveOne(int id) in PersonsController.cs

    1. [HttpGet("{id}")]
    2. [ProducesResponseType(typeof(D_Person), StatusCodes.Status200OK)]
    3. [ProducesResponseType(StatusCodes.Status404NotFound)]
    4. public ActionResult RetrieveOne(int id)
    5. {
    1. var person = _personservice.RetrieveOne(id);
    1. if (person.RowCount == 0)
    2. {
    3. return NotFound();
    4. }
  • lambda_method(Closure , object , object[] )

  • Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(object target, object[] parameters)

  • Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor+SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)

  • Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()

  • Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()

  • Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)

  • Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)

  • Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()

  • Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()

  • Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)

  • Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)

  • Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()

  • Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()

  • Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)

  • Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.Invoke(HttpContext context)

  • Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Attachments (1)
Cami Lawson Accepted Answer Pending Moderation
  1. Tuesday, 16 July 2019 13:01 PM UTC
  2. SnapObjects
  3. # 1

Thanks all.  I did the db table change as David suggested, it did not change the outcome.  Perhaps it would be helpful if Appeon took the documentation a step further and did more than one API to help see how it works.  I have had to move on to other projects for the moment and will get back to this more in a few weeks.

Comment
There are no comments made yet.
Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Friday, 12 July 2019 04:59 AM UTC
  2. SnapObjects
  3. # 2

Hi Cami,

I can't see your model D_Person.

But the following D_Person works in my test. I created a datawindow object in PB. Then used the Generate C# Models feature to create D_Person. And we usually don't need to map C# datatype with database datatype manually.

    [Table("Person", Schema = "Person")]
    [UpdateWhereStrategy(UpdateWhereStrategy.KeyAndConcurrencyCheckColumns)]
    public class D_Person
    {
        [Key]
        public Int32 Businessentityid { get; set; }

        [ConcurrencyCheck]
        public String Persontype { get; set; }

        [ConcurrencyCheck]
        [DefaultValue(typeof(Boolean), "False")]
        public Boolean Namestyle { get; set; }

        [ConcurrencyCheck]
        public String Title { get; set; }

        [ConcurrencyCheck]
        public String Firstname { get; set; }

        [ConcurrencyCheck]
        public String Middlename { get; set; }

        [ConcurrencyCheck]
        public String Lastname { get; set; }

    }

Refer to:

https://www.appeon.com/support/documents/appeon_online_help/powerbuilder/CRUD_Operations_with_.NET_DataStore/index.html

Regards,

Logan

Comment
  1. David Peace (Powersoft)
  2. Friday, 12 July 2019 08:49 AM UTC
I think that important part is Int32:

[Key]

public Int32 Businessentityid { get; set; }
  1. Helpful
There are no comments made yet.
David Peace (Powersoft) Accepted Answer Pending Moderation
  1. Thursday, 11 July 2019 15:56 PM UTC
  2. SnapObjects
  3. # 3

Hi

In my experience (which is not fantastic I must admit) C# & SQL Server are a bit picky about data types and integers. I have fallen foul of this a few time with tinyine, smallint, int and bigint. As we well know these are just numbers but SQL server gets upset when they are mixed. I do not know but I would be temped to define them the exact same type and see if your problem goes away.

Good luck

David

Comment
  1. Cami Lawson
  2. Thursday, 11 July 2019 16:03 PM UTC
Thanks David. It is a test db I got for doing the exercises. I'll have to do some funness to change the type as it has a bunch of table dependencies throughout. I did try changing the type in the declaration but could not find a suitable type to use for a regular int other than int. I'll try modifying the db this afternoon and see what happens.
  1. Helpful
  1. David Peace (Powersoft)
  2. Thursday, 11 July 2019 16:09 PM UTC
I cannot promise it will work, but you need to eliminate the variables. You could try creating a new table with your own definitions and see if that works first.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.