Click here to Skip to main content
15,118,001 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

C#
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 :

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



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

C#
foreach (var item in cpl)
{
TblSellProducts tsp = new TblSellProducts()
{
    // add field
};
context.TblSellProducts.AddObject(tsp);
}
Posted
Comments
Member 9549287 13-Aug-13 15:21pm
   
you should go through linq to entities mapping tutorials. hope these help:

http://msdn.microsoft.com/en-us/library/bb386964.aspx

http://msdn.microsoft.com/en-us/library/dd456828.aspx

http://msdn.microsoft.com/en-us/library/bb896297.aspx
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