C# automatic properties - is it possible to have custom getter with default setter?

后端 未结 5 1109
清酒与你
清酒与你 2021-01-04 13:44

It\'s possible I shouldn\'t even be attempting this in the first place, but here\'s what I have so far:

public List AuthorIDs
{
    get
    {
             


        
5条回答
  •  情话喂你
    2021-01-04 14:50

    There is actually a way of doing that:

    public List AuthorIDs
    {
        get
        {
            var l = new List();
            using (var context = new GarbageEntities())
            {
                foreach (var author in context.Authors.Where(a => a.Books.Any(b => b.BookID == this.BookID)).ToList())
                {
                    l.Add(author.AuthorID);
                }
            }
            return l;
        }
        set{
           this.SetPropertyValue(page => page.AuthorIDs, value);
        }
    }
    

提交回复
热议问题