Dynamic Data Cannot insert the value NULL - asp.net

I 'm working on an ASP.NET Dynamic Data Entities Web Application.
When trying to insert a new entry in one of the tables, with some value in the column_name field, I get the following message :
Cannot insert the value NULL into column 'column_name', table 'DATABASE.dbo.table_name'; column does not allow nulls. INSERT fails.
The column properties are :
Entity Key : True
Nullable : False
Type : String
I believe Dynamic Data is trying to send null value to entity framework for some reason, but I don't know which.
Do you know why Dynamic Data is behaving that way ?
Or have you any idea how to debug the insert process ?
Thanks

I found where the problem come from. A table from the database the model is based contains a trigger. For some reason the model makes an association between the two tables involved in the trigger.

Related

Reference another table in ASP.NET without a foreign key or joining tables

I have read-only access to a database. This database has multiple tables with status codes and one other reference table the gives a name for each code. These tables are not linked by a foreign key and I can't alter the database in any way. I'd like to display the status names in my web-app view instead of the numeric status code, is there a way to do this? Using EF Core 6
I tried to join the two tables but it didn't match the model in the View. I don't know how to remedy this situation without creating a new table (which I can't do)

How to force mapping in copy activity of Azure Data Factory

I am trying to copy data from a cosmosdb container to an Azure SQL database table using Azure Data Factory.
Some of my columns in cosmosdb are not mandatory and might not be defined. The issue is that for every of these columns, I get the following error when running the copy activity :
Data type of column 'MyProperty' can't be inferred from 1st row of data, please specify its data type in mappings of copy activity or structure of DataSet.
However I checked in the mapping tab and the types of these properties are correctly infered to string, and they are well nullable in my SQL stored procedure table type.
I also have the same problem for optional decimal properties where the errors says that the value can't be parsed to Int64, though the infered type in the mapping tab is set to number and not integer...
Here is the mapping I currently have :
And the stored procedure with the table type
CREATE TYPE [dbo].[MyTableType] AS TABLE
(
[Id] varchar(256) NOT NULL PRIMARY KEY,
[SupplierId] varchar(256) NOT NULL,
[SupplierClientId] varchar(256) NULL,
[BuyerId] varchar(256) null
)
CREATE PROCEDURE [dbo].[UpsertItems]
#itemsTable MyTableType readonly
AS
BEGIN
MERGE MyTable AS target
USING #itemsTable AS source
ON (target.Id = source.Id)
WHEN MATCHED THEN
UPDATE SET
SupplierId = source.SupplierId,
SupplierClientId = source.[SupplierClientId],
BuyerId = source.[BuyerId]
WHEN NOT MATCHED THEN
INSERT (Id, SupplierId, SupplierClientId, BuyerId)
VALUES (
source.Id,
source.SupplierId,
source.[SupplierClientId],
source.[BuyerId]);
END
I can't find a way to force the datatype of this property either in the dataset directly of in the mapping tab of the copy activity. How can I fix the issue ?
You can specify the data types if you are creating a new table while copy. But if you are adding or copying to an already existing table, the data type is inferred automatically.
While, auto creating table in copying
If this does not help, please share sample source data and some snips

Issues while selecting values into nullable type property in Simple.Data

I have a integer column in the database which is nullable. So while creating the datamodel i made the property "int?". This way my insert/update statement is working as expected.
However when I try to select data from the table into the same datamodel, the field is not getting populated. What am i doing wrong ? Can somebody please suggest ?
There was a mistake. The database column was in fact "VARCHAR". So I changed the model property to String, and things are now working fine.
So it appears that though Simple.Data is able to select VARCHAR coumn value into int model property, it somehow was failing to convert into int?. Changing model property to String sorted out the issue of both insertion/selection.

Oracle ADF Form Submit Error

I have created a form to insert data into Expenses table. when i'm trying to insert data i got below error.
Attribute ExpensesId in AppModule.ExpensesView1 is required.
I have a Before Insert Trigger to insert ExpensesId to the table. so i don't need to add ExpensesId manually.
how could i resolve this error ?
in this case set the ADF BC type of the expenseId attribute to DBSequence so the framework knows that this is taken care of
Frank

Cannot insert null where field is Guid (object in SqlDataSource)

I have a table which links to another table in the ASP.NET membership schema.
Problem is, all the PKs for the ASP.NET tables are uniqueidentifier so mine has to be too. When I add a SqlDatasource and call its Insert() method, I get the following error:
Cannot insert the value NULL into column 'DiscountCode', table 'CreamDb.dbo.CustomInfo1'; column does not allow nulls. INSERT fails.
The statement has been terminated.
The uniqueidentifier is also treated as an object (its data type), but there is no Guid data type. I had this problem before, but the schema was much simpler so I could fix it.
How can I go about fixing this? If I get rid of the data type part in the markup (so just leave the field/parameter name but not the data type stuff), I get another error so that is not possible.
Thanks
What do you mean by "there is no Guid data type"? What's wrong with System.Guid? Can't you just use Guid.NewGuid(), set the field appropriately, and do the insert?
EDIT: Just to give a bit more meat: attach an event handler to the Inserting event, and populate the field then, via the DbCommand returned by SqlDataSourceCommandEventArgs.Command. Or change the SQL used by the INSERT command to ask the database to populate the GUID field for you.
A popullar approach when dealing with references to the ASP.NET Membership Provider's data is, instead of keeping a proper foreign key to the GUIDs, instead store something like the LoweredUserName in your table. Then, use the Membership Provider's API to interact with the object you need. In some cases, you need an ObjectDataSource abstraction layer to accomplish CRUD scenarios.
Set the default value of the column in SQL Sever to "newid()".
Asp.net won't send the value, and the field will get a new guid.

Resources