Good day! I want to make some extra information for orders. And I think to make extra table in DB with foreign key to Order.Id Fetch 1:1. The scenario is - when I create a new order on this table should also create a new record, and delete scenario should be a cascade. I'm curious how can I make this thing via plugin?
Good day! I want to make some extra information for orders. And I think to make extra table in DB with foreign key to Order.Id Fetch 1:1. The scenario is - when I create a new order on this table should also create a new record, and delete scenario should be a cascade. I'm curious how can I make this thing via plugin?
I think you can use [dbo].[GenericAttribute] table for this.
But if want to make a new table from plugin you can. but note that you can't do foreign key relation bcz of different object context. You have access both table parallel. Both cases you have to delete any row manually.
Subscribe to events Order Entity Inserted and Order Entity Deleted in your plugin code. Please find below is sample code. public class MyPluiginClass : BasePlugin, IConsumer<EntityInserted<Order>>, IConsumer<EntityDeleted<Order>> { public void HandleEvent(EntityInserted<Order> eventMessage) { //TODO: Code to add records when Order is created throw new NotImplementedException(); }
public void HandleEvent(EntityDeleted<Order> eventMessage) { //TODO: Code to delete records when order is deleted throw new NotImplementedException(); } }
So ok I did it. But questions - in the future I want to add some more extra fields to this table. So how it will be? What I really need to do? So, I add a new field in Entity. Then probably I need to make some Code First Migration right?
using System; using System.Collections.Generic; using System.Data.Entity; using System.Data.Entity.Core.Objects; using System.Data.Entity.Infrastructure; using System.Linq; using System.Text; using System.Threading.Tasks;
using System; using System.Collections.Generic; using System.Data.Entity; using System.Data.Entity.Core.Objects; using System.Data.Entity.Infrastructure; using System.Linq; using System.Text; using System.Threading.Tasks;
So ok I did it. But questions - in the future I want to add some more extra fields to this table. So how it will be? What I really need to do? So, I add a new field in Entity. Then probably I need to make some Code First Migration right?
when you add new field to existing entity then you need to add new field in Entity and need to add manually on DB.
it will not automatically update the DB so it will be manual process for adding new field.
sorry but i am not sure that its possible to remigrate on existing entities to add or update fields
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Vous avez encore des questions ou avez besoin d'aide?