Orocommerce Delete an Entity - database

I wanted to delete the entity I created with Entity Management before, but it was just disabled, and then I made changes that I could not remember in the database related to this entity and sometimes I am having problems with this entity while updating the schema.
Is it possible to do this entity hard delete in orocommerce?

Is it possible to do this entity hard delete in orocommerce?
From the management console, you can only soft-delete custom entities.
To hard delete, it is required to write a schema migration that uses Oro\Bundle\EntityConfigBundle\Migration\RemoveTableQuery.
For example, here is the migration that drops an event entity and the related database table:
https://github.com/oroinc/platform/blob/4b2efdbd33792df7fb0da9831b184838591f00b4/src/Oro/Bundle/NotificationBundle/Migrations/Schema/v1_5/DropEventTable.php#L48-L49

Related

EF Code First Migrations and Foreign Key Constraints

Once FK Constraints have been created via Entity Framework Core 1.1 with Migrations in an ASP.NET Core Code First app, would it be ok to temporarily enable/disable the constraints directly in SQL Server without using EF - would it break the migrations created via EF etc? Background: I need to truncate data from a table that has been referenced by several tables via FK's that were created through EF Code First. SQL Server, as expected, complains that you can truncate the table since it's been referenced by a FK etc.
No, it would not break migrations. If you are doing anything on database and then reverting back the schema design of database to earlier state then migration will just run fine. Migrations when applied expect that shape of EF managed objects in database to be remain same (as it would have known earlier). Any temporary change is invisible to migration. And state needs to be same afterwards because when future migrations applied then appropriate objects are present otherwise DDL can cause failure.
Anything you change in the database schema in SQL Server, without the code, will break the migrations. You should delete the foreign key references in the code for the operation you want to do and then recreate them later. Though, be careful, if your data is left in inconsistent state, you might not be able to recreate constraints without losing data.

Reasonable practice for existing db with 75 tables

I'm creating a new visual studio web site using MVC4/webapi that will go against a database of 75 preexisting tables (not perfect in terms of foreign keys, etc.). I'm thinking that I will create an ado.net entity data model and select all my tables. then, when my tables change I will do the "update model".
With my linq2sql projects, I always ran sqlmetal against all my tables all the time to keep things in sync and that worked fairly well.
Is my plan to have all my tables in one ado.net entity data model reasonable? what pitfalls might I run into? Is it better to have lots of ado.net entity data models? I've tried having multiple ado.net entity models in other projects and I seem to constantly be getting my connection strings doubled in my web.config.
I did do a search on SO and did not find any discussions that directly addressed my concern.
If you followed your plan, you would miss out on an opportunity to have an entity model simpler than your database model:
Your application almost certainly doesn't need all 75 tables.
You would be missing the opportunity to consider a series of 1-1 tables as a single entity
You would be missing the opportunity to use inheritance in your model
You would be missing the opportunity to keep junction tables out of your model
You would be losing one of the greatest advantages of Entity Framework over LINQ to SQL: it does not need to stay one-to-one with the database.

Entity Framework 4.2: InsertFunction for Tables without PK

In Entity Framework 4.2, I am trying to insert a value into a table which has no PK. EF gives me the following error:
Unable to update the EntitySet 'ConditionTypesForWebApplications'
because it has a DefiningQuery and no <InsertFunction> element exists
in the <ModificationFunctionMapping> element to support the current
operation.
From the below discussion, I understood that it is possible to tweak that by editing the edmx file but it is not a best case when you are working with DbContext class.
How do you update a table with a foreign key to another table in ADO.Net Entity Model?
Is there any better way of enabling this?
It is same for DbContext with EDMX (DbContext without EDMX doesn't support entities without keys at all). Entity without key is read only unless you manually change EDMX file (be aware that any update model from database will delete your changes unless you buy more advanced tools for EDMX editing) or you will create stored procedure and map it to insert function of the entity.
In short entity should have key because EF should be able to uniquely identify it. Otherwise you can meet other problems in your application.

Do i need to define relationship in SQL Server database if i am using EF and Linq

I am working on a asp.net mvc project and using Linq for all my data related operations. In such cases, do I need to define relationship in the SQL Server database ??
I am using Entity framework and Linq so I think it doesn't matter if I create an E-R diagram(i.e defining relationship) or not.
By 'define relationship' I assume you mean 'Foreign key constraints'. It is always advisable to define constraints in order to maintain data integrity. You should also consider that the database for your project could probably be used by other applications in the future which might be based on other technologies than EF.
If you have relations in DB they will automatically be imported in your EF Model but you always have an option to create the associations manually in the EF Designer if you don't have relations in DB.
See How to manually add association in Entity Framework

How to partially migrate a database to a new system over time?

We are in the process of a multi-year project where we're building a new system and a new database to eventually replace the old system and database. The users are using the new and old systems as we're changing them.
The problem we keep running into is when an object in one system is dependent on an object in the other system. We've been using views, but have run into a limitation with one of the technologies (Entity Framework) and are considering other options.
The other option we're looking at right now is replication. My boss isn't excited about the extra maintenance that would cause. So, what other options are there for getting dependent data into the database that needs it?
Update:
The technologies we're using are SQL Server 2008 and Entity Framework. Both databases are within the same sql server instance so linked servers shouldn't be necessary.
The limitation we're facing with Entity Framework is we can't seem to create the relationships between the table-based-entities and the view-based-entities. No relationship can exist in the database between a view and a table, as far as I know, so the edmx diagram can't infer it. And I cannot seem to create the relationship manually without getting errors. It thinks all columns in the view are keys.
If I leave it that way I get an error like this for each column in the view:
Association End key property [...] is
not mapped.
If I try to change the "Entity Key" property to false on the columns that are not the key I get this error:
All the key properties of the
EntitySet [...] must be mapped to all
the key properties [...] of table
viewName.
According to this forum post it sounds like a limitation of the Entity Framework.
Update #2
I should also mention the main limitation of the Entity Framework is that it only supports one database at a time. So we need the old data to appear to be in the new database for the Entity Framework to see it. We only need read access of the old system data in the new system.
You can use linked server queries to leave the data where it is, but connect to it from the other db.
Depending on how up-to-date the data in each db needs to be & if one data source can remain read-only you can:
Use the Database Copy Wizard to create an SSIS package
that you can run periodically as a SQL Agent Task
Use snapshot replication
Create a custom BCP in/out process
to get the data to the other db
Use transactional replication, which
can be near-realtime.
If data needs to be read-write in both database then you can use:
transactional replication with
update subscriptions
merge replication
As you go down the list the amount of work involved in maintaining the solution increases. Using linked server queries will work best if its the right fit for what you're trying to achieve.
EDIT: If they're the same server then as suggested by another user you should be able to access the table with servername.databasename.schema.tablename Looks like it's an entity-framework issues & not a db issue.
I don't know about EntityToSql but I know in LinqToSql you can connect to multiple databases/servers in one .dbml if you prefix the tables with:
ServerName.DatabaseName.SchemaName.TableName
MyServer.MyOldDatabase.dbo.Customers
I have been able to click on a table in the .dbml and copy and paste it into the .dbml of the alternate project prefix the name and set up the relationships and it works... like I said this was in LinqToSql, though have not tried it with EntityToSql. I would give it shot before you go though all the work of replication and such.
If Linq-to-Entities cannot cross DB's then Replication or something that emulates it is the only thing that will work.
For performance purposes you probably want either Merge replication or Transactional with queued (not immediate) updating.
Thanks for the responses. We're going to try adding triggers to the old database tables to insert/update/delete records in the new tables of the new database. This way we can continue to use Entity Framework and also do any data transformations we need.
Once the UI functions move over to the new system for a particular feature, we'll remove the table from the old database and add a view to the old database with the same name that points to the new database table for backwards compatibility.
One thing that I realized needs to happen before we can do this is we have to search all our code and sql for ##Identity and replace it with scope_identity() so the triggers don't mess up the Ids in the old system.

Resources