0

i'm struggling with LLBLGEN and i guess ORM's in general. i have created an entity, lets use a library example to explain:

i want to display a book object and also return a list of users who have loaned the book. so i need to return the book object which contains a list of users.

DTO Book::
int bookId,
string bookName

additionally i wish to return with my book a collection of users who have loaned the book:

List<user> Loans

loans table might look like this:

int id
int userid
int bookid

currently my loans entity has now created this:

DTO Loans
int id
User user // user entity
Book book // book entity

im struggling to understand how this example would work in llblgen. can anyone assist with guidance or point me in the way of a tutorial? at the moment, when i come up to update my model Book with a new loan associated to a book, im getting stackoverflow errors. i assume this is creating some sort of loop when attempting to update my Book object.

thanks

nologo
  • 5,918
  • 3
  • 36
  • 50

2 Answers2

1

i noticed when running a profiler on SQL that the sql statement didnt include any join statements onto my relationship entities. this was because my domain query didnt include prefetch items for my relationships, i added the following to my query:

        var query = new DomainSearch<T>
                   {    
                       SearchText = searchText,
                       PrefetchItems =
                           {
                               new Prefetch(typeof(Users))
                           }
                   };
nologo
  • 5,918
  • 3
  • 36
  • 50
0

To make sure, you are looking for a list of User entities that have loaned a particular Book entity. Is this the correct use case, or are you looking for a list of User entities that have borrowed the particular book?

Regardless, LLBLGen's support for these cases is great with referencing relationships between entities and using related entities quickly and easily.

Presuming you're looking up a book by unique BookId/ISBN/etc....

// Get the specific book entity
BookEntity book = new BookEntity(bookId);

foreach(UserEntity user in book.users)
{
    // do stuff with list of users
}

It's just that simple assuming you've defined your relationships between entities.

Mark A
  • 5,881
  • 5
  • 26
  • 34
  • This example assumes you are using SelfServicing, which supports lazy loading of related collections. If using Adapter, you would need to manually fetch the related collection yourself using PreFetch paths. – Matt Nov 25 '10 at 14:47