Reflect database change in UI table immediately using .NET Core with Entity Framework - entity-framework

When running the application in a multiuser environment, changes made by one user i.e modifying, adding or deleting records, are not seen by other users until they refresh the page.
What is the best way of doing it?
Thanks.
As for now, I have tried refresh the page automatically every 3 minutes, but I'm looking for a better solution.
Response.Headers.Add("Refresh","180");

Related

keeping database in sync ef core

I have read multiple posts about this but do not have a clear answer yet.
We are transitioning to EF Core 2.0 company-wide, one project at a time.
The challenge is this:
A new project starts and a database is created using code first, migrations etc.
another programmer needs to create a project targeting the same database.
This programmer can use Scaffold-DbContext and generate current models.
However, a new column is needed and this second programmer adds it.
Now...how do we best update the other projects?
Is there something that checks and syncs or shows what is out of sync between your model and a database? Meaning check the database for changes...not the model.
We don't mind buying a tool if that is the best solution.
The solution we have been using, very successfully is the Database project in Visual Studio.
Using that each developer has the project in their solution, changes are made against it locally.
Then we can do a "Schema Compare" inside of VS.
We have been using this successfully for 4 of us the past three weeks extensively with almost no issues.
This has even worked for keeping versions and changes to our stored procedures current.
It works well with VSTS also.
Here are some of the posts I read that helped me understand it:
https://www.sqlchick.com/entries/2016/1/10/why-you-should-use-a-ssdt-database-project-for-your-data-warehouse
https://weblogs.asp.net/gunnarpeipman/using-visual-studio-database-projects-in-real-life
..and this forum had a lot of relevant questions/answers:
https://social.msdn.microsoft.com/Forums/sqlserver/en-us/home?forum=ssdt

Entity Framework Code First Library and Database Update Implications

We have recently begun using Entity Framework for accessing all the various databases we touch on a regular basis. We've established a collection of library projects, one for each of these. For many of them, we're accessing established databases that do not change, and using DB first works just great.
For some projects, though, we're developing evolving databases that are having new fields and tables added periodically. Because these libraries are used by multiple projects (at the moment, just two, but eventually many more), running a migration on the production database necessitates a republish of both/all sites that use that particular DB's library. Failure to update the library on any other site of course produces the error that the model backing the context has changed.
How can we effectively manage the deployment/update of the Code-First libraries to all of the sites that use them each time a change to the database is made?
A year later, here's what we came up with and have been using.
We now include the following line in the Application_Start() method:
Database.SetInitializer<EFLib.MyHousing.MyHousingMVCContext>(null);
This causes it not to throw a fit if the current database model doesn't exactly match what's in the code. While there is still potential for problems if non-backward-compatible changes are made, this allows for new functionality to be added without the need to re-deploy every site that uses these libraries when the affecting changes are not relevant to that particular site.

Updating an SQLite database on the iPhone

I have very little knowledge about app development, but I am updating an existing SQLite database (simple text changes to the html that is stored within the database). Everything works fine, but when I submitted the app to Apple the changes weren't showing when people upgrade (if you download it for the first time - straight from the App Store - it is fine, so the database must be saved to the cache).
Does anyone know how I can overwrite the existing database? People have said to change the file name of the database, but will this make the app run slower (will two databases be stalled in the cache). Also peoples data are stalled on the database (bookmarks etc.) so somehow that info still needs to be retained if possible.
Any help would be appreciated.
i also would recommend you to rename the database. thats the easiest and fastest way. rename your model and set it to the standard.
i am using this solution, too. my app is not running slower then before. just test it.
please also see this two links for adding new models to your project:
create new model version(apple)
How to Add Core Data to an existing Utility Application
I think that change should happened only in the build u r tested and not in you have uploaded on appstore.
So better way u upload it again... With all testing done.

Code First model and deployment of new versions of the software

I'm looking on Entity Framework at the moment and working with Code First example. So far I can see that the framework does not handle model changes easily: whenever I want to add another field to a class/table, framework drops the entire database and creates it from the scratch.
Similar behaviour I saw in (N)Hibernate. (I could be wrong here, it was long time ago)
That is ok, as long as I work on tutorial. When a real-life project is involved, you can't afford to drop a database every time you need a new field in a table.
Just imagine scenario, you are working on a project with many clients. Every client has their own database. In release 1.0.1 I need to add a new field to one of the tables. If I drop database in my dev environment - not a big deal. (Still, I need to run a script to populate test data every time DB is dropped, and sometimes even this is no viable)
But what do I do when I need to deploy this new version? Make a SQL script to update client's databases without dropping them? then deploy binaries?
But how is this better than doing database mods separate from code changes?
(sorry for my bad english)
This is exactly why Code First Migrations exists. Take a look here (automatic migrations) and here (code-based migrations)

How to hook an action after SaveChanges is successful

Our product has to be interfaced with multiple client/partner systems. For example, when a person is added/updated we have to notify changes to a 3rd-party system, for example by calling a web service or creating a xml file in a folder, etc.
We need a "hook" after SaveChanges has successfully persisted changes in the database.
Lots of information can be found about how to execute business logic when saving changes (before changes are persisted in the database), but less about executing logic after changes are persisted.
After investigating, I think to use the following:
// Persist data
cxt.SaveChanges(false);
// TODO: execute business logic that can get data changes
// Discard changes and set entities as unmodified
ctx.AcceptAllChanges();
Does anyone have a better solution for this scenario?
I know this question is a bit old, but figure that I would add this for anyone else searching on this topic.
I would recommend checking out EFHooks. The official version is a bit stale (e.g. .NET 4 only), but I have forked the project and published a new NuGet package, VisoftInc.EFHooks.
You can read more about both packages in this post: http://blogs.visoftinc.com/2013/05/27/hooking-into-ef-with-efhooks/
Basically, EFHooks will let you hook into EF (e.g. PostInsert or PostUpdate) and run some code. The hooks are Pre/Post for Insert/Update/Delete.
One thing to note is that this is based on the DbContext, so if you are still using the ObjectContext for EF, this solution won't work for you.
You can override savechanges, then do the updating of the 3rd party systems at the same time as you save the data to the database.
see: http://thedatafarm.com/blog/data-access/objectcontext-savechanges-is-now-virtual-overridable-in-ef4/