Individual relationship with subsonic

How can you create a one-to-one relationship in Subsonic? For example, I have a table called “Readings,” and each Reading has only one book, however Subsonic returns IQueryablebooks. I want her to return only one book. Thanks.

+3
source share
2 answers

I assume that you are using the ActiveRecord template to generate your code.

Inside ActiveRecord.tt you will see a section that looks like this:

 public IQueryable<<#=fk.OtherClass #>> <#=propName #>
        {
            get
            {
                  var repo=<#=Namespace #>.<#=fk.OtherClass#>.GetRepo();
                  return from items in repo.GetAll()
                       where items.<#=CleanUp(fk.OtherColumn)#> == _<#=CleanUp(fk.ThisColumn)#>
                       select items;
            }
        }

, . , , - .

, .

+1

, :

public partial class Reading 
{
    private Book _book;
    public Book Book 
    {
        get 
        {
            if (_book == null)
                _book = this.Books.SingleOrDefault();
            {
                return _book;
            }
        }
        set
        {
            _book = value;
        }
    }
}

Book, Iqueryable.

- , , , , .

: , , -

+1

Source: https://habr.com/ru/post/1712970/


All Articles