AX 2012 AIF Service don't retrieve table on XML - axapta

for a project I need to change the AIF service called "SalesSalesEInvoice". In particular, I need to retrieve the CustPaymModeTable on the result XML.
In the query used by the service, this table is present and is joined with CustTrans (relationship based on PaymMode field).
We debugged the service execution and we've observed that the table is not retrieved because it is not linked via surrogate key (AifSecurityInference.inferField()).
Did you ever had (and solved) that problem?
How can we force the recovery of the table when the join is not based on recid?

It looks like there is a range set in CustPaymModeTable. So please verify if there is record exists with that range value.

Related

Use ConditionExpression to limit insert when ID doesn't exist in other table

Simple thing. While inserting data to table A I have a HashKey id and additional hash index for column ex_id, which is kind of a foreign key in table B.
When inserting a new data into table A I would like to create an exception whenever data is inserted with value in column ex_id that doesn't have a correspondent entry in table B.
I thought that ConditionExpression is the way to go, but can't make it work - probably missing something obvious. Tried to use contains()...
Any ideas?
As per my knowledge this would not be possible at DynamoDB end because there are no relationship between the tables.
What you can do is that you can have a condition at the application level, which checks on its own and throw an exception before inserting the value in table A. (You can query table B for that "Id" if found then insert else throw exception)
DynamoDB does not natively support any kind of foreign key support, everything works on a per table basis, per key basis. DynamoDB's approach is to handle such logic at the client level. For example see the dynamodb transactions client. This library allows you to perform transactions across tables which either all succeed or all rollback.
For your case, I would first make a getItem request to table B (use consistent read) if it exists then write to table A.
Then I would enable streams on table A and write a lambda function to check if any data violations get written to the table.

Providing default value for unmapped column in SQL Compare

Is it possible to provide a default value or a query to provide a value to an unmapped column in the target table using Redgate SQL Data Compare?
To explain the scenario I have a configuration database that holds settings data for several database instances. The data is all in the same shape, but the config database has an additional InstanceID field in most tables. This allows me to filter my compare to only compare against the InstanceID relating to the source Instance database. However if I generate Insert scripts they fail because the Target Instance ID fields are non nullable. I want to provide a default value that is then used in the Insert Scripts. Is this doable?
SQL Data Compare doesn't have an easy way of doing this I'm afraid.
There is one way to do it - you could create a view that selects everything from the source table along with a computed column, which just provides the "default value" that you want to insert. Then you can map the view to the table in the target database and compare them, deploying from the result.
I hope this helps.

How do I include a third party SQL table into a asp.net code first web application?

It would be nice to be able to access the third party table in the same ApplicationDbContext that is generated by code first. But ultimately I really want to be able to join on the table in a linq query that translates into a single sql query (dont want it to make two database calls because I am joining two database contexts)
The table is a zipcodes table purchased from a third party. It does not have a unique id as code first requires, so I would have to give it one i guess?
If you're not using Code First Migrations to manage the database, you could just create a model for the zip codes table. The EF model for the table and the table itself don't necessarily have to match, so you could create a class to represent a zip code table record, and set a key for the zip codes entity even if the database table itself doesn't have one. You would have to be sure that the chosen key is unique or you would get unexpected results.
If you're using Code First Migrations, the same thing applies, but you can also run the SQL script itself in a DbMigration or in the DbMigrationsConfiguration.Seed.

Biztalk Insert or Update in to database using the SQL bindings

I have a requirement where the data from one database has to be selected and inserted or updated in to the other database depending on the destination. I have used the DBBinding to select from the source.In the destination do I have to use stored procedure to do this or selecting Insert and Update in the DBBinding will work for this.
You can use Insert or Update unless you have some complex requirement to do in stored procedure.
You should probably use a stored procedure for this and perform an upsert within it. You could use a Composite Operation to send all the data across to SQL in one transaction or investigate using a Table Value Parameter so you can send multiple rows to the stored proc (depending on the number of rows!).
To do this you would need to create a MAP between your source data and the Composite Schema.
This way you are only concerened with the schema of the stored procedure and the Composite Schema.
See:
https://msdn.microsoft.com/en-us/library/dd788136.aspx
HTH

What methods are available to monitor SQL database records?

I would like to monitor 10 tables with 1000 records per table. I need to know when a record, and which record changed.
I have looked into SQL Dependencies, however it appears that SQL Dependencies would only be able to tell me that the table changed, and not which record changed. I would then have to compare all the records in the table to find the modified record. I suspect this would be a problem for me as the records constantly change.
I have also looked into SQL Trigger's, however I am not sure if triggers would work for monitoring which record changed.
Another thought I had, is to create a "Monitoring" table which would have records added to it via the application code whenever a record is modified.
Do you know of any other methods?
EDIT:
I am using SQL Server 2008
I have looked into Change Data Capture which is available in SQL 2008 and suggested by Martin Smith. Change Data Capture appears to be a robust, easy to implement and very attractive solution. I am going to roll CDC on my database.
You can add triggers and have them add rows to an audit table. They can audit the primary key of the rows that changed, and even additional information about the changes. For instance, in the case of an UPDATE, they can record the columns that changed.
Before you write/implement your own take a look at AutoAudit :
AutoAudit is a SQL Server (2005, 2008) Code-Gen utility that creates
Audit Trail Triggers with:
Created, CreatedBy, Modified, ModifiedBy, and RowVersion (incrementing INT) columns to table
Insert event logged to Audit table
Updates old and new values logged to Audit table
Delete logs all final values to the Audit table
view to reconstruct deleted rows
UDF to reconstruct Row History
Schema Audit Trigger to track schema changes
Re-code-gens triggers when Alter Table changes the table
What version and edition of SQL Server? Is Change Data Capture available? – Martin Smith
I am using SQL 2008 which supports Change Data Capture. Change Data Capture is a very robust method for tracking data changes as I would like to. Thanks for the answer.
Here's an idea.You can have a flag on each table that every time a record is created or updated is filled with current datetime. Then when you notice that a record has changed set its flag to null again.Thus unchanged records have null in their flag field and you can query not null values to see which record has changed/created and when (and set their flags to null again) .

Resources