【问题标题】:Xamarin.forms sqlite-net lookup an IdXamarin.forms sqlite-net 查找 Id
【发布时间】:2017-07-03 08:19:29
【问题描述】:

提前致谢,

我正在使用 SQLite-net Frank Krueger 和 James Montemagno 根据此视频编写的代码:Motz Code Live Sqlite 和 GitHub:2015-08-21 SQLite-net PCL

一切正常,但想知道如何查找 BusinessEntityBase.cs 中包含的 Id 字段

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

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

我有一个使用此 BusinessEntityBase 的表,因此使用了 Id 字段:

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;

}

我有一个页面,我希望更新该表中的记录。我知道 ActivityNameDB 的值(它是唯一的),我希望使用它来查找 Id 字段的值,以便我可以更新正确的记录。

如何获取此 Id 值?

或者我应该把 Id 值带到这个页面吗?

【问题讨论】:

    标签: c# xamarin.forms sqlite-net


    【解决方案1】:

    我只会在两页之间携带价值。

    否则,您将不得不调用数据库以获取 id,这是无缘无故的大量额外工作。

    【讨论】:

    • 谢谢。我想我只需要被告知。 :)
    • 传递 1 个值总是比查看一个值备份要好,祝你好运,如果你发现这个答案足够好,别忘了标记它;)
    • 谢谢。这就是我现在所做的所有工作。
    猜你喜欢
    • 1970-01-01
    • 2021-09-17
    • 2017-05-30
    • 2019-04-07
    • 2019-11-18
    • 2018-11-23
    • 2019-07-01
    • 1970-01-01
    • 2018-06-21
    相关资源
    最近更新 更多