【发布时间】:2009-09-17 10:36:35
【问题描述】:
我正在尝试使用 Subsonic3 中的 SimpleRepository 功能 - 首先,我必须非常感谢 RobC - Subsonic 真的很棒,我迫不及待地想看到 SimpleRepository 的更多更新。我是迁移方法的忠实拥护者(开发人员/类驱动,而不是从数据库开始)。
我看过这里的帖子: Parent and Child object in SimpleRepository 但我还是有点迷茫。
如果我定义了这些类:
public class Permit {
public int PermitID {get; set;}
public string Number { get; set; }
public DateTime? DateIssued { get; set; }
public Product product { get; set; }
}
public class Product
{
public int ProductID { get; set; }
public string Value { get; set; }
}
然后我想为许可证保存数据,我应该怎么做?我应该在 Permit 类中定义一个 ProductID,然后以编程方式将它们链接起来吗?或者下面的代码应该工作吗?
var repo = new SimpleRepository("ECPermit", SimpleRepositoryOptions.RunMigrations);
var permit = new Permit();
var product = new Product();
permit.Number = "apermit";
permit.DateAdded = DateTime.Now;
product.Value = "this is a product";
repo.Add(permit);
permit.product = product;
repo.Add(product);
这是创建 Permit 和 Product 表,但它们之间没有链接。我究竟做错了什么? 谢谢
【问题讨论】:
-
+1。我们刚刚开始评估是否要使用 SubSonic。有一次我的同事问它如何处理相关表、连接等。你的 A J 的问题和 Adam 的回答告诉我它至少可以工作。
标签: subsonic3 simplerepository