Mapping an entity to 2 tables - asp.net

I have a position class that i want to be able to write to the database. I currently have a entity for the class that is mapped to the database. I want to because to have the class insert data into one table and update entries in the other table. One table is for current positions and the other is for historical positions. Is it possible to map an entity to 2 tables and have it update 1 table and insert into the other?

Wouldn't it be easier to have a Trigger on the Update that Insert automatically a copy of the data in your history table?

Just don't do this. Use a database insert trigger.

I would make 2 different entities for this. If you want this to map to a single entity in your application you should write a data access class that (based on the data of your single entity) determines whether to do an update or an insert.
And I would personally never ever use a trigger for such a thing as this is business logic to me that needs to be exposed in the application so it can be tested.

Related

Does Axapta 4.0 have a functionality to map data between different tables

I have two tables Cashdisc and Convertterm, Does axapta have a functionality where Convertterm.code can be related to CashDisc.Code so that whenever converterm.code changes it can be updated in CashDisc.Code.
Yes. I think you're referring to a table relation.
If you want a table to update another table, you can do that through code, but I think you're talking about how the table naturally functions with table relations.
See here https://msdn.microsoft.com/en-us/library/bb190076(v=ax.10).aspx
You need to write custom code on Convertterm update method after super to update the Cashdisc table.
If you create table relation in child table and if you set validate property to yes, then you can restrict child data creation without a parent record.

filling a grid with from two different record (table) sources

I was wondering if there is any way to populate a table using two different records. My records have the same primary keys, but when I am adding the specific fields to my grid I have this error:
More than one data (key) in one scroll.
I tried to make a Control view field in my primary record, and then refer the new record fields as relative fields but in this case the data is not populating in my grid. Any help or hint will be much appreciated.
I've only done this where the 2nd record is a Derived/Work record.
Can you create a view that combines both records, and put the view in the grid? FYI, peoplesoft let's you update the data in a view, which is not typical in an oracle db system.
Ok guys finally after all discussion, and much try rounds I figured out how to do this.
You need to add a draw a grid beside your old grid and populate it with a new record, which has dynamic view (dynamic sql). The only important case there, is you need to make sure the order of your fields in your records, are in the same order of your fields in the SELECT statement of your sql. Otherwise you will see
an SQL error
.
Try to make a field as display control field which is acting as primary key for its native table and as Foreign key for some other record.. A field needs to be made related if is being fetched from some other record... that is from the record which is not under current consideration. I think this way one can fetch data into grid or scroll respectively from multiple records.

Create new column in query using doctrine2

I'm working on symfony2 project using doctrine2, I have an issue about creating a new button for user connected to a form to add 10 new fields with 10 values of course and 10 columns in DB:
that means when a user click "add new" button so he can adding one field X with XV value and creating one colomun "X" too in database , then second field Y with YV... until 10.Also XV AND YV are the same type of field for example "decimal".
I don't have problem with adding a new field in form using ajax,but my questions are :
1- How to create a new column in a table in DB with doctrine2 and insert value too?
2- how to update Class Entity and Class form too automatically in the same time when a new column is created?
First of all I have to admit I did not understand the goal you are trying to achieve completely. But I am almost positive, that there is a conceptual mistake in your design.
You have to distinguish between the following two concepts:
DML (Data Manipulation Language), such as INSERT, UPDATE or DELETE data in/from the database, meaning that you create new records (INSERT).
DDL (Data Definition Language), such as CREATE TABLE (to create a new database relation) or ALTER TABLE (to add new columns to the database).
You are trying to use DDL (ALTER TABLE statements according to your description) to dynamically add new columns to your database, which is not effective and not good practice at all. You should have an extremely good reason to do it that way (e.g. if the system you are building is a database administration tool or something like this...).
I would heavily recommend you to completely rethink and redesign your architecture and use DML to achive your goal. I am sure your problem can be solved by designing a flexible data structure and not adding new columns, but inserting new records in a dynamic database.
After you have redesigned your database structure it will be very easy to implement your task with Symfony and Doctrine.

Whats the most efficient way to create an orchestration which updates an Oracle database?

I am creating my first orchestration in Biztalk and am having trouble coming up with an efficient way to update a database (specifically, up to 3 different tables).
The user calls our service with an inbound message matching a schema which contains emplid (unique id) and then a bunch of name-value pairs (see source schema in this picture). The "name" corresponds to a column in a table (e.g. if the name is "employeename" it corresponds to the NAME column of the EMPLOYEE table). The value of course is the new value that the user wants that column to be updated to.
So they could pass in an update message which only applies to 1 table, 2 tables, or all 3, depending on the fields they want to update for the passed in employee.
I am currently approaching it as 3 separate updates with 3 table adapters (one for each table, one of which is pictured above) but Im having trouble working with the different cases of if they pass in updateValuePairs for all 3 tables, versus only one or only for two tables (the other queries still attempt to run and fail). Am I approaching this right? Or is there a better way to accomplish what I am trying to do?
i would try i different way in order to implement cleaner solution,
create a Store-Procedure that handle the logic to which table to go
than you will need only on mapping and one LOB adapter instead of the 3 you got now
over view solution
1.receive input in the orchestration
2.mapping the input to the Stored procedure generated schema
3.sending the mapped data to the DB/LOB adapter into the DB
here is a link that can help you (im assuming you use biztalk 2010):
How to use Oracle Stored Procedure

Edit a read-only view

I have a column and I would like to edit some of its rows. The problem is that the table is a view so I cannot edit the rows. How would I proceed to solve this problem?
SQLite doesn't let you update views. But it does allow triggers on views. So you can write an INSTEAD OF UPDATE trigger that makes the appropriate modifications to the underlying table.
As dan04 pointed out, you can use triggers to update views (like in most other databases). For sqlite, see http://www.sqlite.org/lang_createtrigger.html#instead_of_trigger
Example with a view called "myview", containing a table "my_t2"
CREATE TRIGGER myview_update INSTEAD OF UPDATE ON myview
BEGIN
UPDATE my_t2 SET field1 = new.field1, field2 = new.field2 WHERE my_t2.key = old.key;
END
If it's a view, it's not a table. The data for the view is drawn from one or more other tables. Edit the underlying table and when you examine the data in the view it will reflect the changes you made.
A SQL View is a virtual table, which is based on SQL SELECT query. Essentially a view is very close to a real database table (it has columns and rows just like a regular table), except for the fact that the real tables store data, while the views don’t. The view’s data is generated dynamically when the view is referenced. A view references one or more existing database tables or other views. In effect every view is a filter of the table data referenced in it and this filter can restrict both the columns and the rows of the referenced tables.
If you wish to modify the data in your table, you cannot do so with a view. SQL Views are always read-only. If you want to modify your table outside of the View, then use something like an UPDATE or ALTER TABLE statement.

Resources