简体   繁体   中英

Xamarin.forms sqlite-net lookup an Id

Thanks in advance,

I am using SQLite-net Frank Krueger and the code written by James Montemagno as per this video: Motz Code Live Sqlite and GitHub: 2015-08-21 SQLite-net PCL

I have it all working, but want to know how I can look up the Id field that is included in the BusinessEntityBase.cs

public class BusinessEntityBase : IBusinessEntity
{
    public BusinessEntityBase()
    {
    }

    #region IBusinessEntity implementation
    [PrimaryKey, AutoIncrement]
    public int Id
    {
        get; set;
    }
    #endregion

I have a table that uses this BusinessEntityBase and therefore the Id field:

public class ActivityItemDB : BusinessEntityBase


{

    public string ActivityNameDB { get; set; } = string.Empty;
    public string ActivityCategoryDB { get; set; } = string.Empty;
    public string ActivityImageDB { get; set; } = string.Empty;
    public string ActivitySelectedDB { get; set; } = string.Empty;
    public int ActivityAbilityDB { get; set; } = 0;

}

I have a page, where I wish to update a record in that table. I know the value of the ActivityNameDB (which is unique), I wish to use this to look up the value of the Id field, so that I can then update the correct record.

How do I do get this Id value?

Or should I have carried the Id value through to this page?

I would just carry the value between the 2 pages.

Otherwise you'll have to do a call to the database to get the id out which is a lot of extra work for no reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM