ConductedClever
ConductedClever

Reputation: 4295

EF does not add object even in the table object

I have the following code:

    public ServiceResult Add(TPost value)
    {
        try
        {
            Table.Add(CastFromCreateViewModel(value));

            foreach (var item in Table)
            {

            }

            DataHelper.SaveChanges();

            return ServiceResult.NewServiceResult(true,null);
        }
        catch(Exception ex)
        {
            return ServiceResult.NewServiceResult(false, ex);
        }
    }

the Table comes from the child:

    protected override DbSet<Data.Product> Table
    {
        get
        {
            return DataHelper.db.Products;
        }
    }

ande the caster is implemented in the child too:

    public override Product CastFromCreateViewModel(ProductCreateViewModel obj)
    {
        return obj;
    }

now after adding the object to Table obj, even in the next foreach, the result is not including the new object. No error and no exceptions!

Upvotes: 2

Views: 126

Answers (1)

Mojtaba Ahmadzadeh
Mojtaba Ahmadzadeh

Reputation: 106

I think your problem is related to this code "DataHelper.db" . I've had this problem before, and the reason was that I had written the wrong code and i had a new context on saveChange

Upvotes: 4

Related Questions