私がよく理解していれば、1つActivity
は1つを持っていCustomer
ます。その場合は、Activity
クラスにリレーションを追加する必要があります。
[Table( Name = "Customers" )]
public class Customer
{
[PrimaryKey, Identity]
[Column(Name = "CustomerId"), NotNull]
public string Id { get; set; }
[Column(Name = "Name")]
public string Name { get; set; }
}
[Table( Name = "Activities" )]
public class Activity
{
[PrimaryKey, Identity]
[Column(Name = "ActivityId"), NotNull]
public string Id { get; set; }
[Column( Name = "Customer" )]
private int? customerId;
private EntityRef<Customer> _customer = new EntityRef<Customer>( );
[Association(IsForeignKey = true, Storage = "_customer", ThisKey = "customerId" )]
public Customer Customer{
get { return _customer.Entity; }
set { _customer.Entity = value; }
}
}
このテーマに関する良い記事
編集:
関連付けが機能しない場合のウォークアラウンド:
[Table( Name = "Activities" )]
public class Activity
{
[PrimaryKey, Identity]
[Column(Name = "ActivityId"), NotNull]
public string Id { get; set; }
[Column( Name = "CustomerId" )]
public int? CustomerId;
}
次のようなアクティビティから顧客を取得できます。
var activity = db.Activities.FirstOrDefault()
var customer = db.Customers.FirstOrDefault(c => c.Id = activity.CustomerId);