0
У меня есть эти два классазамок ActiveRecord ленивым получить идентификатор
[ActiveRecord("Customers", Lazy=true)]
public class Customer : ActiveRecordBase<Customer>
{
[PrimaryKey(PrimaryKeyType.Identity, Access = PropertyAccess.AutomaticProperty)]
public virtual int Id { get; private set; }
[Property]
public virtual string Name { get; set; }
[HasMany(Lazy = true)]
public virtual IList<Order> Orders { get; set; }
}
[ActiveRecord("Orders", Lazy=true)]
public class Order : ActiveRecordBase<Order>
{
[PrimaryKey(PrimaryKeyType.Identity, Access = PropertyAccess.AutomaticProperty)]
public virtual int Id { get; private set; }
[Property]
public virtual string Product { get; set; }
[BelongsTo(Lazy = FetchWhen.OnInvoke)]
public virtual Customer Customer { get; set; }
}
Я хочу, чтобы выбрать все заказы и Еогеасп из них, получить идентификатор клиента. Так я это делаю:
using (new SessionScope())
{
var orders = Order.FindAll();
foreach (var o in orders)
{
int id = o.Customer.Id;
}
}
Он работает, но он создает ВЫБЕРИТЕ фразу для каждого вызова o.Customer.Id. Теперь заказ уже имеет идентификатор клиента, так как я могу его получить, не пересматривая базу данных?
Да, это работает, СПАСИБО !! – yshdev