代码之家  ›  专栏  ›  技术社区  ›  stoic Kobus Kleynhans

亚音速简单存储库-持久私有属性

  •  0
  • stoic Kobus Kleynhans  · 技术社区  · 14 年前

    我正在利用亚音速单纯形储存库

    我有一堂课:

    public class X{public string abc {get; set;}private string def {get; set;}}
    

    property "def" is only set within that class and i don't want the property to be visible externally, but for some reason when i save the object using Repo.Save(x) the private property is not persisted to the DB

    有什么帮助吗?

    1 回复  |  直到 14 年前
        1
  •  1
  •   Anton    14 年前

    Set up a two data models, one that represents X in the front-end (public, visible) and one that represents X in the back-end (private, hidden):

    namespace App.BackEnd // classes here are used for database storage
    {
        public class X
        {
            public string abc { get; set; }
            public string def { get; set; }
    
            public FrontEnd.X ToFrontEnd()
            {
                return new FrontEnd.X
                {
                    abc = abc
                };
            }
        }
    }
    
    namespace App.FrontEnd // classes here are used for public interfaces
    {
        public class X
        {
            public string abc { get; set; }
        }
    }