How to avoid generating database table everytime - entity-framework

I am using MVC 3. I use Model first approach.
I created the Product Entity, in model folder. Which contains
ProductID
Name ---properties.
then, I create the SQL table from that model,It generates SQL table perfectly.
(I right click on model image and selects the option 'Generate database from model...'
then SQL window pop ups which contains all the DB scripts and I execute it.)
Now problem comes when, If I want to make changes in that model.
I have to recreate the table each time,so my data get lost.
whether, I have to generate SQL table every time when I make change in model?
How to avoid it?

Related

How do I generate a list of views dependent on a certain table in postgresql?

I need to update a mapping table in postgresql, but of course it won't allow me to replace/drop the original table as there are dependencies.
The error message details does list the dependent views, but I'd like to generate a list programmatically so that I can make temp views while I drop my original mapping table and migrate the views back afterwards.
Prefer not to do this in SQL Shell incidentally. Any pointers would be much appreciated.

How do you change a table's schema?

We have a MySQL Workbench project with two tabs (two schemas/two databases).
If we create a table in the first tab, it's attached to the schema
magikweb_dev_igcweb.
If we create a table in the second tab, it's attached to the schema
magikweb_dev_igcweb_archive.
If we copy-paste/duplicate a table from the first tab to the second tab, the resulting table remains in the first schema. How can you change a table's schema?
Each schema is linked with a specific database, so when we use the "Synchronize Model..." feature, it links all the tables properly.
Use the model tab. You can cut out a table from one schema tab and insert it into another.
The cut-and-paste method described in another answer works well for tables with no foreign keys, and for a reasonable number of tables.
An alternative that preserves foreign keys is to export the model as a SQL script, edit it, and then import the new script into a new model.
Using MySQL Workbench v6.3:
File -> Export -> Forward Engineer SQL Script
Carefully edit SQL script. Replace references to one schema with the other, for the tables you want to move. Do this both for CREATE TABLE commands and foreign key references.
File -> New Model
File -> Import -> Reverse Engineer SQL Script
Unfortunately you will then need to recreate any diagrams. But that can be straightforward if you have the original diagram as reference (take a screenshot or export it to PNG or PDF.)
Follow this simple steps (never miss step 4 and 5) :
Open Model Tab
Choose source schema. In my case, I want to copy table users from schema abc_develop_v1 to schema abc_develop_v2 then paste to diagram . So I choose schema abc_develop_v1, right-click table users then Copy 'users'
Go to the targeted schema. In my case is schema abc_develop_v2, right-click then Paste 'users'
Next, copy table users from schema abc_develop_v2. Right-click table users then Copy 'users'
Go to your diagram and Paste 'users'.
That's all. Your table is ready in your diagram with the right schema :-)
Notes: You can double check by double-click on the table in your diagram, and look at the right corner. It will show the Schema name.
I found a less painful way to do this.
Save and backup your diagram and your schema.
Display schema's name before table's names in diagram. This will make the next step easier.
Right-click on the tables which are on the wrong schema, and select "Copy SQL to clipboard". Paste the script in a new SQL window. Repeat for each table you want to migrate.
Edit the script to change the schema name. Watch for any miss in entries, the wrong schema might be a reference at any line. Mine was mydb, which I don't remember creating. Execute the script. Now you have the tables on the right schema.
Synchronize your model. Be sure to check "Update the model" for each missing table, otherwise, the tables will be deleted from the schema :)
Drag'n'drop the newly created tables into the diagram. Then remove the ones which are using the wrong schema. Tip: tables that are not in diagram won't display a dot next to their name.
Optionally, you can delete the faulty schema from the model so this never happens again. Be sure to know what you're doing first!

Some fields are missing in the fieldexplorer. How to show all fields?

i'm using Crystal Reports with my ERP-System. There have been predefined reports i now want to change.
In the field-explorer are some tables which have been renamed for better readability. But those tables are missing some fields, i want to use. If i connect the whole table again, all fields are there. Is there a way to display all fields in the predefined tables.
I tried to refresh the Database but nothing changes. If i delete the predefined table and then rename the new one to the old one, so i can use all predefinded formulas, all used fields in the report get deleted. I would need to recreate the whole report then.
Thanks for the help
If it is truly the same table and is not showing all the fields then you need to do "Database > Verify Database". That will force CR to refresh the structure of the table (instead of just the data). If this doesn't add the missing fields then the table in the report is actually a different object.
To see what the table/view the report is actually using go to "Database > Set DataSource Location" and look at the properties node for that table. It will show if it is a table/view/SP and what the true object name is.
If you want to replace the existing table with a different table you go to "Database > Set DataSource Location" again. Highlight the existing table in the top window, connect and highlight the replacement table in the bottom window. Then click update. Crystal will replace one table with the other and all of the fields in the report that exist in the new table will be mapped automatically. Note that the new table will keep the alias of the original table. If you are unsure if the table was updated you can look at the properties node in the top window to see the change.

Using Select query, nothing merges onto Crystal report

I have a Crystal template that I am modifying in developer because we are changing the datasource from an Access file to our Oracle DB. I created a database field that accurately connects to Oracle and added a select statement that because pulls a field from a particular table
select s.field from table s;
On the right hand side, under database fields, I see my command and can right click and browse the data, which right now returns two values.
I also made a formula field using an Azalea barcode function that calls the values (I think, this is where stuff is going wrong, I guess)
The formula field is
BarcodeC39ASCII({Command.field})
So this should take the data and format it into the barcode, except when I use print preview or print out the report, no data is merged.
I've tested this by creating a new formula field with just the Command.field, and still no data is merged. I imagine there is something really obvious that I am missing and would appreciate any input.
So unless I misunderstood your question, you are changing your datasource from Access DB to Oracle DB, correct? Assuming that the database structure remains the same then all you should need to do is go into Database -> Set Datasource Location and set the datasource location from the Access DB to the Oracle DB and your existing report should work as it did. You might have to map some fields, but that should be the extend of it. Is that what you are trying to do?
Chris

SqlDataAdapter Update

Can any one help me why this error occurs when i update using sqlDataadapter with join query
Dynamic SQL generation is not supported against multiple base tables.
You have a "join" in your main query for your dataset (The first one in the TableAdapter with a check by it). You can't automatically generate insert/update/delete logic for a TableAdapter when the main query has multiple tables referenced in the query via a join. The designer isn't smart enough to figure out which table you want to send updates to in that case, that is why you get the error message.
Solution. Ensure that your main query only references the table you want the designer to write insert/update/delete code for. Your secondary queries may reference as many tables as you want.
It was in the case that i was trying to set value for identity column in my datarow. Simply i deleted the code to set value for identity column and it will work.
My Scenario:
Database:
uin [primary, identity]
name
address
Whenever i tried to set the datarow("uin") the error occurs. But works fine with datarow("name") and datarow("address").
Hope it works for you too