【问题标题】:Exist attribute in Realm Db which like NotMapped?Realm Db 中是否存在类似于 NotMapped 的属性?
【发布时间】:2021-05-12 10:41:30
【问题描述】:

我将应用程序中的数据库从 sqlite EF 更改为 realmDB,但我找不到任何 NotMapped 等效属性。

    Public string MainCoordY { get; set; }
    [NotMapped] private double Y => double.Parse(MainCoordY .Replace(".", ","));

【问题讨论】:

    标签: c# .net attributes realm


    【解决方案1】:

    Realm 将自动忽略没有设置器的属性,因此您上面的示例不需要显式属性。此外,具有非自动访问器的属性也将被忽略。最后,[Ignored] 属性告诉 Realm 不要处理属性,大致相当于[NotMapped]

    public class Person : RealmObject
    {
        // Ignored because it doesn't have a setter
        public string ClassName => "Person";
    
        private string name;
    
        // Ignored because it's not an auto property
        public string Name
        {
            get => this.name;
            set => this.name = value ?? throw new Exception("Name must not be null");
        }
    
        // Ignored because of the attribute
        [Ignored]
        public int Age { get; set; }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-20
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 2018-06-28
      • 1970-01-01
      • 1970-01-01
      • 2011-02-27
      相关资源
      最近更新 更多