activa / iridium

Iridium - Lightweight .NET ORM for mobile, desktop and server applications
MIT License
22 stars 8 forks source link

Simple update not working? #20

Closed Amplificator closed 2 years ago

Amplificator commented 2 years ago

I'm trying o get familiar with Iridium and so far I'm liking it.

I'm trying to do basic CRUD but my update statement doesn't seem to work.

using (var db = new DbContext())
{
var template = db.Templates.FirstOrDefault(x => x.Title == item);

template.Title = txtTitle.Text;
template.Text = txtPredefinedMessage.Text;

db.Templates.Update(template);
}

Debugging shows that it gets the template just fine and fields update but the issue is committing the update to the database. I've also tried with just db.Update(template) and .Save as well - what am I missing?

activa commented 2 years ago

I'm trying o get familiar with Iridium and so far I'm liking it.

I'm trying to do basic CRUD but my update statement doesn't seem to work.

using (var db = new DbContext())
{
var template = db.Templates.FirstOrDefault(x => x.Title == item);

template.Title = txtTitle.Text;
template.Text = txtPredefinedMessage.Text;

db.Templates.Update(template);
}

Debugging shows that it gets the template just fine and fields update but the issue is committing the update to the database. I've also tried with just db.Update(template) and .Save as well - what am I missing?

Does the Templates table have a primary key? Update() or Save() requires a primary key

Amplificator commented 2 years ago

It does. The SQL code is this: https://paste.mozilla.org/5TarCTNp

activa commented 2 years ago

That should work the way you wrote it. Can you share the declaration of the Template class?

Amplificator commented 2 years ago

I have this:

public IDataSet<Templates> Templates { get; set; }

namespace hoejdata_cpsms
{
    public class Templates
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Text { get; set; }
    }
}

That is the entire class.

activa commented 2 years ago

Although this should work in theory, can you try adding the [Column.PrimaryKey] attribute to the Id field?

Amplificator commented 2 years ago

That worked, thank you! :)

activa commented 2 years ago

Thanks. I'll make a note of that. It may be an issue with the MySql driver