如何在.Net Maui中的SQLite Table类定义中创建计算列?

n53p2ov0  于 2023-05-23  发布在  SQLite
关注(0)|答案(1)|浏览(169)

如何在.Net Maui中的SQLite Table类定义中创建计算列?
这是table……

[SQLite.Table("ItemHist")]
    public class cl_ItemHist : TableData
    {
        [NotNull, ForeignKey(typeof(cl_Stores))]
        public int Store_id { get; set; }
       
        [NotNull]
         public DateTime PurchDate { get; set; }
        
        [NotNull, ForeignKey(typeof(cl_Items))]
        public int Item_id { get; set; }
       
        [NotNull] 
        public float ItemQty { get; set; }
       
        [NotNull]
        public float TotalPrice { get; set; }
       
        [ForeignKey(typeof(cl_SaleCodes))]
        public int SaleCode_id { get; set; }

        [NotNull, ForeignKey(typeof(cl_Uom))]
        public int UnitPriceUom_id { get; set;}
        
        [NotNull, DefaultValue(0)]
        public int Purchased { get; set; }

        // References cl_Stores
        [OneToOne(CascadeOperations = CascadeOperation.CascadeRead)]
        public cl_Stores StoreName { get; set; }
        
        // References cl_Items
        [OneToOne(CascadeOperations = CascadeOperation.CascadeRead)]
        public cl_Items ItemName { get; set; }
        
        [OneToOne(CascadeOperations = CascadeOperation.CascadeRead)]
        public cl_Items ItemSize { get; set; }

        // References cl_SaleCodes
        [OneToOne(CascadeOperations = CascadeOperation.CascadeRead)]
        public cl_SaleCodes SaleCode { get; set; }

        // References cl_Uom from cl_Items
        [OneToOne(CascadeOperations = CascadeOperation.CascadeRead)]
        public cl_Uom Uom { get; set; }

    }

要包括的计算列包含三个现有列。(总价/(项目大小 * 项目数量))

vojdkbi0

vojdkbi01#

要从sqlite中排除计算属性,请将其标记为[Ignore]

[Ignore]
public float MyComputedColumn => . . .;

https://learn.microsoft.com/en-us/xamarin/android/data-cloud/data-access/using-sqlite-orm#sqlite-attributes
然而,你提到了“动态”。如果您需要立即更新display,则在对影响该列的三个属性进行任何更改时,您将需要在这三个属性的setter中添加额外的代码。类cl_itemHist需要实现INotifyPropertyChanged。

相关问题