Question

Unable to insert records in OrderProduct table

Hi,

I'm trying to insert a record in [OrderProduct] table through Data Sevice from a .Net application using visual studio.

I have an OrderId and ProductId which I want to insert in [OrderProduct] table but unable to do so. It is throwing an error.

One of the reasons I found in the academy's article is mentioned in the image :

Here' s is my sample code for reference.

var insertOrderProductrQuery = new InsertQuery()

                {

                    // Root schema name.

                    RootSchemaName = "OrderProduct",

                    // New column values.

                    ColumnValues = new ColumnValues()

                    {

                        // Key-value collection.

                        Items = new Dictionary()

                        {

                            {

                                "Name",

                                new ColumnExpression()

                                {

                                    ExpressionType = EntitySchemaQueryExpressionType.Parameter,

                                    ColumnPath = "Name",

                                    Parameter = new Terrasoft.Nui.ServiceModel.DataContract.Parameter()

                                    {

                                        Value = orderItem.Product.Name,

                                        DataValueType = DataValueType.Text

                                    }

                                }

                            },

                            {

                                "Notes",

                                new ColumnExpression()

                                {

                                    ExpressionType = EntitySchemaQueryExpressionType.Parameter,

                                    ColumnPath = "Notes",

                                    Parameter = new Terrasoft.Nui.ServiceModel.DataContract.Parameter()

                                    {

                                        Value = string.Empty,

                                        DataValueType = DataValueType.Text

                                    }

                                }

                            },

                            {

                                "ProductId",

                                new ColumnExpression()

                                {

                                    ExpressionType = EntitySchemaQueryExpressionType.Parameter,

                                    ColumnPath = "ProductId",

                                    Parameter = new Terrasoft.Nui.ServiceModel.DataContract.Parameter()

                                    {

                                        Value = bpmProductId,

                                        DataValueType = DataValueType.Text

                                    }

                                }

                            },

                            {

                                "CustomProduct",

                                new ColumnExpression()

                                {

                                    ExpressionType = EntitySchemaQueryExpressionType.Parameter,

                                    ColumnPath = "CustomProduct",

                                    Parameter = new Terrasoft.Nui.ServiceModel.DataContract.Parameter()

                                    {

                                        Value = string.Empty,

                                        DataValueType = DataValueType.Text

                                    }

                                }

                            },

                            {

                                "Quantity",

                                new ColumnExpression()

                                {

                                    ExpressionType = EntitySchemaQueryExpressionType.Parameter,

                                    ColumnPath = "Quantity",

                                    Parameter = new Terrasoft.Nui.ServiceModel.DataContract.Parameter()

                                    {

                                        Value = orderItem.Quantity,

                                        DataValueType = DataValueType.Float

                                    }

                                }

                            },

                            {

                                "UnitId",

                                new ColumnExpression()

                                {

                                    ExpressionType = EntitySchemaQueryExpressionType.Parameter,

                                    ColumnPath = "UnitId",

                                    Parameter = new Terrasoft.Nui.ServiceModel.DataContract.Parameter()

                                    {

                                        Value = "917f764e-62e6-df11-971b-001d60e938c6",

                                        DataValueType = DataValueType.Text

                                    }

                                }

                            },                            

                            {

                                "PrimaryPrice",

                                new ColumnExpression()

                                {

                                    ExpressionType = EntitySchemaQueryExpressionType.Parameter,

                                    ColumnPath = "PrimaryPrice",

                                    Parameter = new Terrasoft.Nui.ServiceModel.DataContract.Parameter()

                                    {

                                        Value = orderItem.Product.Price,

                                        DataValueType = DataValueType.Money

                                    }

                                }

                            },

                            {

                                "Price",

                                new ColumnExpression()

                                {

                                    ExpressionType = EntitySchemaQueryExpressionType.Parameter,

                                    ColumnPath = "Price",

                                    Parameter = new Terrasoft.Nui.ServiceModel.DataContract.Parameter()

                                    {

                                        Value = orderItem.Product.Price,

                                        DataValueType = DataValueType.Money

                                    }

                                }

                            },

                            {

                                "PrimaryAmount",

                                new ColumnExpression()

                                {

                                    ExpressionType = EntitySchemaQueryExpressionType.Parameter,

                                    ColumnPath = "PrimaryAmount",

                                    Parameter = new Terrasoft.Nui.ServiceModel.DataContract.Parameter()

                                    {

                                        Value = orderItem.Order.OrderTotal,

                                        DataValueType = DataValueType.Money

                                    }

                                }

                            },

                            {

                                "Amount",

                                new ColumnExpression()

                                {

                                    ExpressionType = EntitySchemaQueryExpressionType.Parameter,

                                    ColumnPath = "Amount",

                                    Parameter = new Terrasoft.Nui.ServiceModel.DataContract.Parameter()

                                    {

                                        Value = orderItem.Order.OrderTotal,

                                        DataValueType = DataValueType.Money

                                    }

                                }

                            },

                            {

                                "TaxId",

                                new ColumnExpression()

                                {

                                    ExpressionType = EntitySchemaQueryExpressionType.Parameter,

                                    ColumnPath = "TaxId",

                                    Parameter = new Terrasoft.Nui.ServiceModel.DataContract.Parameter()

                                    {

                                        Value = "c6b3420e-f46b-1410-cf89-00155d043204",

                                        DataValueType = DataValueType.Text

                                    }

                                }

                            },

                            {

                                "OrderId",

                                new ColumnExpression()

                                {

                                    ExpressionType = EntitySchemaQueryExpressionType.Parameter,

                                    ColumnPath = "OrderId",

                                    Parameter = new Terrasoft.Nui.ServiceModel.DataContract.Parameter()

                                    {

                                        Value = bpmOrderId,

                                        DataValueType = DataValueType.Text

                                    }

                                }

                            },

                            {

                                "CurrencyId",

                                new ColumnExpression()

                                {

                                    ExpressionType = EntitySchemaQueryExpressionType.Parameter,

                                    ColumnPath = "CurrencyId",

                                    Parameter = new Terrasoft.Nui.ServiceModel.DataContract.Parameter()

                                    {

                                        Value = "915e8a55-98d6-df11-9b2a-001d60e938c6",

                                        DataValueType = DataValueType.Text

                                    }

                                }

                            }

                        }

                    }

                };

 

I have tried every possible column to insert. Please do suggest me the way to insert records in [OrderProduct] table. It will be great if you can share a piece of code for it.

Thank you.

Like 0

Like

1 comments

Dear Jaymita,

Unfortunately, it is not possible to determine exactly the cause of the issue now. In order to find the cause of the issue, please provide us with the text of the error. 

Please note that we do not recommend using DataService for adding data to the database.

Best regards,

Norton

Show all comments