none
ObjectContext.SaveChanges() doesn't saves record in database RRS feed

  • Question

  • I am very new to Entity Framework and got stuck in one place and need some assitance. Currently I am using .NET 3.5 with VS2010.

    Now about problem.

    The Entity has got seperate stored procedures to Insert, Update and Delete operation which I mapped to the Entity created via EDM wizard. The Entity is called HistoryPrice. I have also created a new calss clled Index with a method InsertPrice. Following is the code of InsertPrice.

    public virtual void InsertPrice(double price, DateTime runDate)

    {

    using (DBOAPXFirmEntities indexContext = new DBOAPXFirmEntities())

    {

    IndexHistory indexPrice = new IndexHistory();

    indexPrice.IndexID = _indexId;

    indexPrice.IndexValue = price;

    indexPrice.IndexValuePrec = 1;

    DateTime priceDate;

    if (runDate.DayOfWeek == DayOfWeek.Monday)

    {

    priceDate = runDate.AddDays(-3);

    }

    else if (runDate.DayOfWeek == DayOfWeek.Sunday)

    {

    priceDate = runDate.AddDays(-2);

    }

    else

    {

    priceDate = runDate.AddDays(-1);

    }

    indexPrice.FromDate = priceDate;

    idexPrice.ThruDate = priceDate;

    if (indexContext.Connection.State == System.Data.ConnectionState.Closed)

    {

    indexContext.Connection.Open();

    }

    indexContext.AttachTo("AdvIndexHistories", indexPrice);

    int num = indexContext.SaveChanges(true);

    }

    }

    Reason for executing stored procedure is to integrate the 3rd party software with our custom build version. So I can't have Entity without custom SP for INsert, Update and delete.

    Now after SaveChanges(), record is not getting inserted into the database. Any Ideas?

    Tuesday, June 1, 2010 3:02 PM

Answers

All replies