Object - Assignment problem (Linq to sql classes)

Discussion in 'Databases' started by pratikmehta9, Jul 22, 2009.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi All, I am having following issue.....
    here is my code..

    public int Add(BWS.DB.DAL.ProductMaster product, string strColorSizeIds)
    {
    try
    {

    ProductDataDataContext objDataContext = new ProductDataDataContext();
    if (strColorSizeIds.Length > 0)
    {
    string[] strArrayColorSize = strColorSizeIds.Split('_');
    for (int i = 0; i < strArrayColorSize.Length; i++)
    {
    product.ChildProducts.Add(new ChildProducts()
    {
    BarCode = product.BarCode,
    CanInventorize = product.CanInventorize,
    ColorId = Convert.ToInt32(strArrayColorSize.Split(',')[1]),
    SizeId = Convert.ToInt32(strArrayColorSize.Split(',')[0]),
    CompanyId = product.CompanyId,
    Description = product.Description,
    haveColorSizeMatrix = false,
    id = 0,
    ImageUrl = product.ImageUrl,
    isSerialNoReq = product.isSerialNoReq,
    MinInventoryLevel = product.MinInventoryLevel,
    ParentProdId = product.id,
    ProductClassId = product.ProductClassId,
    ProductCode = "0",
    ProductFamilyId = product.ProductFamilyId,
    ProductSuppliersCostGrids = product.ProductSuppliersCostGrids ,
    SellingPrice = product.SellingPrice,
    IsActive = product.IsActive
    });
    }
    }
    objDataContext.ProductMasters.InsertOnSubmit(product);
    objDataContext.SubmitChanges();

    return 1;

    }
    catch
    {
    return -1;
    }
    }

    ProductSuppliersCostGrids is my class in same datacontext and I set the relationship it to the productmaster class.

    My problem is when I used above code(
    ProductSuppliersCostGrids = product.ProductSuppliersCostGrids) to insert the same suppliers list to childproducts, It's only added to first child product, not even in the main product and other child products..

    Why?????????????
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page