tags:

views:

39

answers:

3

I have the following class that can create/delete and list entities:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Backend.Models
{
    public class PaisRepository
    {
        private EnviosDataContext db = new EnviosDataContext();

        public IQueryable<Pai> FindAll()
        {
            return db.Pais;
        }

        public Pai Get(int id)
        {
            return db.Pais.FirstOrDefault(x => x.ID == id);
        }

        public void Add(Pai pai)
        {
            db.Pais.InsertOnSubmit(pai);
        }

        public void Delete(Pai pai)
        {
            db.Pais.InsertOnSubmit(pai);
        }

        public void Save()
        {
            db.SubmitChanges();
        }
    }
}

How can I update a model?

A: 

Try db.Pais.ApplyChanges(pai);

e36M3
My apologies, this is for EF.
e36M3
A: 

Pai p = PaisRepository.Get(1); p.Someproperty = x; PaisRepository.Save();

James Connell
A: 

From a separate class:

public void UpdatePai(int id, string field1, string field2, int field3)
{
    PaisRepository repository = new PaisRepository();
    Pai pai = repository.Get(id);

    pai.Field1 = field1;
    pai.Field2 = field2;
    pai.Field3 = field3;
    pai.Save();        
}
Neil T.