I am developing an WP8 application that uses a database to store its data.
Now i need to replace a column or at least remove a column and add another one instead.
DatabaseSchemaUpdater is not helping here as it only allows to add columns.
Is there a best practice or an "bullet proof" way to achieve that?
I thought about opening the old database and copy its content to the a new database but then i need to keep track of different schemas and models, because i can only read from a table if i have model class that matches the schema of it.
EDIT:
Ok, i found the answer here: Unused columns, tables, and databases
Related
I'm setting up a data warehouse (in SQL Server) together with our engineers we got almost everything up and running. Our main application also uses SQL Server as backend, and aims to be code first while using the entity framework. In most tables we added a column like updatedAt to allow for incremental loading to our data warehouse, but there is a many-to-many association table created by the entity framework which we cannot modify. The table consists of two GUID columns with a composite key, so they are not iterable like an incrementing integer or dates. We are now basically figuring out the options on how to enable incremental load on this table, but there is little information to be found.
After searching for a while I mostly came across posts which explained how it's not possible to manually add columns (such as updatedAt) to the association table, such as here Create code first, many to many, with additional fields in association table. Suggestions are to split out the table into two one-to-many tables. We would like to prevent this if possible.
Another potential option would be to turn on change data capture on the server, but that would potentially defeat the purpose of code first in the application.
Another thought was to add a column in the database itself, not in code, with a default value of the current datetime. But that might also be impossible / non compatible with the entity framework, as well as defeating the code first principle.
Are we missing anything? Are there other solutions for this? The ideal solution would be a code first solution, or a solution in the ETL process without affecting the base application, without changing too much. Any suggestions are appreciated.
I'm still learning MVC and have gone through several online tutorials. But I'm missing something sort of vital to my application, so this is a general question not necessarily requiring code examples to answer. If you can just steer me in the right direction in conceptual terms...
My application is completely read-only to the database, I don't need or want to write back. I need to pull data from multiple tables in one database, which are the exact same schema, into what I think would be a single model that I can then filter, then display the results. To complicate things somewhat, the table names need to be variables, these tables are built upstream on the fly using the date as part of the table name.
The tables are television automation schedules, different table for each day, but each contain a number of fields for scheduled time, house ID, title, etc. I need to get several days into one model (I think), and then I'm going to query a different database that will tell me for each row in the table whether the House ID exists on a video server or not. I want to then display the list of rows that do not exist in the video server.
I have an example in VB but feel like I should tackle this in C# as it seems to be more universally supported.
I don't think I can use VS tools to create a model from the database table since the table name is different every day.
So is the proper plan of attack to load the multiple table data into one model?
Maybe I don't even need a model in the true sense of the word, there's no binding required to be able to write the data back to the db. I just essentially need to load the table data into an array, doesn't need to continue to be bound to the db, that I can then analyze and figure out which of these items don't exist in the server.
Thanks!
Scenario : I have an existing database, say "DemoDB". It has many tables already there. These tables are used in my existing application using LINQ to SQL or ADO.Net technology. Now I have a requirement where I have to add a new table "NewTable" in DemoDB and do the CRUD operation on that. I want to use "Code First Approach" for simplicity. I have defined new class for "NewTable" in my application.
Problem : When I execute my application it removes all the existing tables for my database. I do not want to create classes for existing tables. Only NewTable is remaining there in my database.
Please suggest if there is any cleaner and simpler way to achieve this.
I am not sure whether this would work, but you can research more on this:
Database.SetInitializer<YourDbContext>(null) in the Global.ASAX.
Good Luck !!
We have a requirement on our project for custom fields. We have some standard fields on the table and each customer wants to be able to add their own custom fields. At the moment I am not interested in how this will work in the UI, but I want to know what the options are for the back end storage and retrieval of the data. The last time I did something like this was about 10 years ago in VB6 so I would be interested to know what the options are for this problem in today's .Net world.
The project is using SQL server for the backend, linq-to-sql for the ORM and a C# asp.net front end.
What are my options for this?
Thanks
There are four main options here:
actually change the schema (DDL) at runtime - however, pretty much no ORM will like that, and generally has security problems as your "app" account shouldn't normally be redefining the database; it does, however, avoid the "inner platform" effect inherent in the next two
use a key-value store as rows, i.e. a Customer table might have a CustomerValues table with pairs like "dfeeNumber"=12345 (one row per custom key/value pair) - but a pain to work with (instead of a "get", this is a "get" and a "list" per entity)
use a single hunk of data (xml, json, etc) in a CustomFields single cell - again, not ideal to work with, but it easier to store atomically with the main record (downside: forces you to load all the custom fields to read a single one)
use a document database (no schema at all) - but then: no ORM
I've used all 4 at different points. All 4 can work. YMMV.
I have a similar situation on the project I'm working on now.
Forget about linq-to-sql when you are having a flexible database schema. There is no way to update the linq-to-sql models on the fly when the DB schema changes.
Solutions:
Keep an extra table with the table name the values belong to , column name , value etc
Totally dynamically change your table schema each time they add a field.
Use a NOSQL solution like mongoDB or the Azure Table Storage. A NOSQL solution doesn't require a schema and can be changed on the fly.
This is a handy link 2 read:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:10678084117056
You're referring to an EAV model (entity-attribute-value).
Here's an article: http://hanssens.org/post/Generic-Entity-Attribute-Value-Model-e28093-A-POCO-Implementation.aspx
I am working on a project that requires the use of multiple databases that for the most part are completely identical but some columns might be missing. How do you get NHibernate to handle this for instance i have a table with 4 columns an index and 2 data coloumns that will always be availible but a singe customer does not want the column in their database.
as this is part of a legacy application migration i do not have the luxury of dictating the database format or even change the databases. anybody have any ideas of how to do this. I cannot get NHibernate shards to work with this either.
KR
Nicky
I don't know of a way to tell NHibernate to ignore columns that are otherwise mapped.
I would look at creating multiple mappings files for the different databases and then depending on your environment configure your SessionFactory using the correct mapping files.
This may seem like a little more work to setup initially but it makes it very clear that in database X you have columns A-B-C and in database Y you only have columns A-B.