Hi,
I have address1 and address2, I want to be able to join and bring the entire relation of each address.
Sometimes I need one address but sometimes I need both.
For some reason, I’m not getting any data in the address object.
var frm = db.From<User>().Join<Address>();
var rowsC = db.Select<User>(frm);
public class User
{
public long Id { get; set; }
[Index]
public string Name { get; set; }
public DateTime CreatedDate { get; set; }
[References(typeof(Address))]
public long? Address1Id {get;set;}
[Reference]
public Address Address1 {get;set;}
[References(typeof(Address))]
public long? Address2Id {get;set;}
[Reference]
public Address Address2 {get;set;}
public override string ToString() => Name;
}
If you don’t want the predefined behavior you’d need to select the main table without references in addition to a custom select to select the reference you want.
If LoadSelete brings all the relations, what’s the point in using join? anyway, it will bring all.
Can you please explain what are you referring to? the example that I posted is the same as the docs.
Maybe some more context will help.
I have a page and I want to present 100 users in a list, the User entity has 15 references. the list should present only 8 references.
I want to do it in one query, so I thought use Join to do that, but when I use LoadSelect, either way, it will load all.
How can I run one query with left joins and only 8 specific references?
LoadSelect loads an entity with references, that’s specifically what the API does, the entity references on your model is so it can be used by Load* APIs, the APIs do let you specify which references to include, but it’s not done with a single query, it requires an additional query per reference type, but if you don’t want the Load* APIs behavior you wouldn’t use it.