nHibernate set column value when entity is changed? - asp.net-mvc-3

I need to set date column with current date time whenever related entity or table has been updated using nHibernate?

You can use Interceptors as described here http://nhibernate.info/doc/nh/en/index.html#objectstate-interceptors
The example given on this page will solve your problem if you use the event "OnFlushDirty"

Related

Laravel - Automatically store history in column

Can anyone help me to automatically save the history of all changed columns in a model to a history column in the same table as JSON format with column(s) name, original value, changed to, changed by?
I am looking for Traits like centralized function to use in all models.
I am using Laravel 8 with PostgreSQL.
This answer is maybe outdated since it is Laravel 4. But if it works, it is quickest way to insert log in DB wherever save() method is called for that model.
https://stackoverflow.com/a/20694395/13893004

facade.edit does not change the database

I am working on a JSF project that deals with MySQL DB.
in my backbean method I did:
entityFacade.edit(entity object);
after that I wanted to make sure of the changes, I queried my database to retrieve the edited record, However, the retrieved values are the old ones. it is like entityFacade.edit(entity object); was not made.
I solved this problem by doing this
entityFacade.remove(entity object);
entityFacade.create(entity object);
But the problem is that the object has ID which is auto-increment & I want to keep the old ID.
I don't get why the edit does not change values. what are the possible causes of this problem?
Looking forward to your answers, experts.
For those who are facing the same problem, I solved it as follows:
The problem was not with the facade.edit()
it was with the queries.
Try facade.find(id) to retrieve the records from the database instead of queries. The retrieved records will show the edited data.

ZF2 form validation against bounded entity

i have an entity with an end date property. If the user edits the entity and changes the date, it shouldn't be allowed that the new date is before the date it was before. Is it possible to get the bounded entity in my validator to check the dates or how can i solve that?
Thanks in advance!
If you are using doctrine 2 you can use/extend the ObjectExists validator (Using a query to find the entity you are interested in) and then add some custom validation to the entity like checking the date field.
Refer to the Doctrine 2 documentation for details on the ObjectExists validator.

EntityFramework code-first, run a database update script after DropCreate

I'm trying to find some nice work arounds for the issues of computed columns in code first. Specifically, I have a number of CreatedAt datetime columns that need to be set to getdate().
I've looked at doing this via the POCO constructors, but to do that I must remove the Computed option (or it won't persist the data), however, there is no easy to way ensure the column is only set if we are inserting a record. So this would overwrite the CreatedAt each time we update.
I'm looking to create an alter script that can be called after the DropCreate that would go through and alter various columns to include the default value of getdate().
Is there an event to hook into something like OnDropCreateCompleted where I could then run additional SQL
What would be the best way handle the alter script? I am thinking just sending raw sql to the server that would run.
Is there another way to handle the getdate() issue that might be more graceful and more inline with code first that I'm missing?
Thanks
You can just make custom initializer derived from your desired one and override Seed method where you can execute any SQL you want to use - here is some example for creating such initializer.
If you are using migrations you can just the custom SQL to Up method.

Dynamically setting MaxLength property of a DataColumn with DataAdapter

I have a datatable that I'm filling with SqlDataAdapter.Fill(). Is there a way to dynamically assign the MaxLength property to each string datacolumn to the maximum allowed by that column in the database?
So I googled for a while and found that the DataAdapter has another method besides Fill which is: FillSchema(), which includes the database schema into the DataTable. Since all I wanted to bring was the MaxLength property what I did was load the schema into another table and loop through the columns assigning the value to each one.
Of course if you wanted to keep all the constraints in the database within your table, then you'd need no loop and just load the schema into the datatable.
PedroC88's answer worked. To clarify the code needed for any newbies. Just above my adapters fill method, I wrote the fillschema method. The (SchemaType)2 argument is required. There are 2 different schematypes (1 and 2) and 2 is recommended as it applies existing table mappings (though I have no idea what this means).
myAdapter.FillSchema(dataTable, (SchemaType)2);
myAdapter.Fill(dataTable);
In this code 'myAdapter' is the name of my adapter and 'dataTable' is the name of my data table.

Resources