Hi, I'm new to BLToolkit, so please advise. Do I use mapping and saving code right?
I have 2 entities, one is independent (Broker), other contains FK from first (Account).
First class with mapping:
[TableName("BROKER")]
public abstract class Broker
{
[MapField("BROKER_ID"), PrimaryKey, Identity]
public int BROKER_ID { get; set; }
[MapField("NAME")]
public string Name { get; set; }
[Association(ThisKey = "BROKER_ID", OtherKey = "Broker.Id")]
public abstract List<Account> Accounts { get; set; }
}
Second class:
[TableName("ACCOUNT")]
[MapField("BROKER_ID", "Broker.Id")]
public abstract class Account
{
[MapField("NAME")]
public string Name { get; set; }
public abstract Broker Broker { get; set; }
[MapField("ACCOUNT_ID"), PrimaryKey, Identity, NonUpdatable(IsIdentity = true)]
public abstract int Id { get; set; }
}
Then I try to generate data and save them to DB.
private static Account InsertAccountWithIdentity()
{
var account = GenerateAccount();//I create and set Name field there
var broker = GenerateBroker();//I create and set Name field there
account.Broker = broker;
broker.Accounts.Add(account);
var id = dbManager.InsertWithIdentity(broker);
broker.BROKER_ID = Convert.ToInt32(id);
return account;
}
This code inserts both entities, but table field ACCOUNT.BROKER_ID remains empty. It shouldn't be! What is wrong?
Thank you in advance.