You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible for you to create another class or use an expando object?
For example, having something like this:
publicstaticclass MyExtensions
{publicstaticList<ExpandoObject>ExpandProducts<T>(thisList<Product>products){varlist=newList<ExpandoObject>();foreach(var product in products){foreach(var a in product.aList){// WOULD be better if you could create another class but otherwise, expando could work finevarexpando=new ExpandoObject();
expando.ProductId = product.ProductId;
expando.ListValue =a;
list.Add(expando);}}returnlist;}}// Map
DapperPlusManager.Entity<ExpandoObject>("productListData").Table("ProductListData");// Insert
connection.BulkInsert(products);
connection.BulkInsert("productListData", products.ExpandProducts());
(code has not been tested so might contains some coding mistake)
I have a model as below:
And the result in the model is like this:
ProductId: 99901
ProductName: Product01
aList
How do I add this model to database like below?
Table Products:
ProductId | ProductName
99901 | Product01
Table ProductListData:
ProductId | ListValue from aList
99901 | wq222-33e2-2022-2a2s2-2ss4
99901 | as222-3e44-2002-2a2s2-2ss4
99901 | as2xg-3e44-2002-2a2s2-2ss4
I solve the problem with different methods, but I cannot change the structure of this model. I have to conform to this structure of the model.
I hope I was able to explain my problem.
Thank you
The text was updated successfully, but these errors were encountered: