Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to insert generic collection to table with linq to entity
my generic collection is

class Sellprod
    public int IDStuff { set; get; }
    public string namestuff { set; get; }
    public int Number { set; get; }
    public Int64 OncePrice { set; get; }
    public int Discount { set; get; }
    public Int64 Sellmultipleprice { set; get; }


and my table fields is :

IDsell	int	Unchecked
IDDocSell	int	Unchecked
IDStuff	int	Unchecked
Number	int	Unchecked
SellPrice	bigint	Unchecked
Discount	bigint	Unchecked
SellMultiplePrice	bigint	Unchecked

i can use below code but i know is not good and i don't know what is good

foreach (var item in cpl)
TblSellProducts tsp = new TblSellProducts()
    // add field
Member 9549287 13-Aug-13 15:21pm    
you should go through linq to entities mapping tutorials. hope these help:
virusstorm 13-Aug-13 16:03pm    
Keep in mind that no matter what you do, you can't do bulk inserts. You will have to loop over every entry and insert them one at a time. If you want to do bulk copy, use SqlBulkCopy class.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900