views:

232

answers:

1

I validate data for a table made in the linq designer in the event OnValidate.

This event is fired when I insert records, but not is fired when I update records.

I have this code:

public bool Save(int id, string marca, string modelo, string año, string motor,
    bool disponible, RuleList issues)
{
    Usado u;
    if (id == 0)
    {
        u = new Usado();
        u.IdUsado = GetNextIdUsado();
        u.FechaCreacion = DateTime.Now;
    }
    else
    {
        u = GetUsadoById(id);
    }
    u.Marca = marca;
    u.Modelo = modelo;
    u.Año = año;
    u.Motor = motor;
    u.Disponible = disponible;
    if (id == 0)
    {
        DataBase.Usados.InsertOnSubmit(u);
    }
    return Execute(issues, DataBaseOperation.Save);
}

When id is equal to zero I do an insert, otherwise I do an update.

Why might this happen? Thank you in advance for any clue.

A: 

Does your update result in a changed object or are you assigning all values that were the same as the original values? You might have to make sure that some value is different in order for LINQ to do anything with it. Check the changes with GetChangeset().Updates.Count. (Where's your SubmitChanges?)

BlueMonkMN