开发者

subsonic 3.0 active record update

I am able to retrieve database values and insert database values, but I can't figure out what the Update() syntax should be with a where statement.

Environment -> ASP.Net, C#

Settings.ttinclude

    const string Namespace = "subsonic_db.Data";
    const string ConnectionStringName = "subsonic_dbConnectionString";

    //This is the name of your database and is used in naming
    //the repository. By default we set it to the connection string name
    const string DatabaseName = "subsonic_db";

Retreive example

var product = equipment.SingleOrDefault(x => x.id == 1);

Insert Example

   equipment my_equipment = new equipment();

    try
    {
        // insert
        my_equipment.parent_id = 0;
        my_equipment.primary_id = 0;
        my_equipment.product_code = product_code.Text;
        my_equipment.product_description = product_description.Text;
        my_equipment.product_type_id = Convert.ToInt32(product_type_id.SelectedItem.Value);
        my_e开发者_如何转开发quipment.created_date = DateTime.Now;
        my_equipment.serial_number = serial_number.Text;

        my_equipment.Save();

    }
    catch (Exception err)
    {
        lblError.Text = err.Message;
    }

Edit: Think that I was just too tired last night, it is pretty easy to update. Just use the retrieve function and use the Update() on that.

    var equip = Equipment.SingleOrDefault(x => x.id == 1);

    lblGeneral.Text = equip.product_description;

    equip.product_description = "Test";
    equip.Update();


Resolved. View answer above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜