- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在玩弄 Subsonic 3 的简单存储库,但在理解如何处理外键时遇到了瓶颈......
如果我有一个产品对象包含
int ID;
string name;
string description;
Category category;
int categoryID (this one is just to persist the product's categoryID to the DB)
and a category object containing
int ID;
string name;
如何使用存储库返回所有产品的列表及其实例化的类别对象?
目前我已经编写了一个 linq 查询,它加入了 product.categoryID = category.ID 这一切都很好,但是当我 .ToList() 这个查询的结果时,产品的类别没有实例化。
有没有办法做到这一点,还是我必须为每个产品手动实例化类别?
谢谢,
保罗
最佳答案
你需要让 linq 来填充它,
使用类似
var query = from product in repo.All(Product)
将 categoryItem 加入 repo.All(Category)
product.CategoryId 等于 categoryItem.Id
选择新的{
ID = product.ID,
名称 = 产品.名称,
description = product.description,
categoryId= product.CategoryId
类别 = 类别项
};
关于c# - 亚音速 3 - SimpleRepository,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1176594/
我刚开始使用 SubSonic 3 并使用 SimpleRepository 方法。在桌面应用程序中使用时 SimpleRepository 类的预期生命周期是多少? 您是否希望每次想要访问数据库时都
在研究 SubSonic 的新 SimpleRepository 时,我发现调用 更新()方法总是抛出 NullReferenceException .这在 3.0.0.3 版本中包含的示例 MVC
如果我希望能够在对象之间建立一对多的关系,那么在 Subsonic 的 SimpleReporitory 中它将如何工作? 我是否必须创建一个桥接对象,然后在运行时构建我的父对象,还是内置了此支持?
希望 SubSonic SimpleRepository 有一个解决方案/补丁,我可以在其中指定具有默认值的列/属性,以便它使用默认值集填充数据库。 我仍在阅读 SubSonic 文档,只是遇到了那个
我有一个数据库表(Profile)来描述一个人。该表有一列“性别”(整数)。在 .NET 部分我有: public enum Sex { Male = 1, Female = 2 } public c
我正在玩弄 Subsonic 3 的简单存储库,但在理解如何处理外键时遇到了瓶颈...... 如果我有一个产品对象包含 int ID; string name; string description;
我一直在探索 Sub Sonic 3 的 SimpleRepository 并且对它非常满意,但对交易有疑问。我知道使用像“AddMany”和“DeleteMany”这样的方法将在单个事务中自动执行所
我如何使用 SimpleRepository 在 SubSonic 3 中处理关系?例如:拥有作者和书籍(见下文)我希望在保留书籍时保留指定的作者。 [Serializable] public cla
我正在使用 Subsonic 的 SimpleRepository,我正在尝试编写一些单元测试,这样它们就不会触及数据库,但我无法弄清楚 SimpleRepository 是否可以针对内存列表工作(比
我正在尝试使用 Subsonic3 中的 SimpleRepository 功能 - 首先,我必须对 RobC 表示衷心的感谢 - Subsonic 真的很棒,我迫不及待地想看到 SimpleRepo
我有这个玩具代码,工作正常,使用 MySQL var r = new SimpleRepository("DB", SimpleRepositoryOptions.None); var q =
在 SubSonic 3.04 的 SimpleRepository 中,我似乎无法在 lambda 表达式中执行 Contains 操作。这是一个简单的例子: SimpleRepository re
我想在我的项目中使用 subsonic 3.0 SimpleRepository,但是有一个问题: 如果我的表名像 产品 等然后我无法从数据库中获取任何数据, 因为 subsonic 会生成像“Sel
我正在尝试使用 Rihino 模拟来模拟亚音速 SimpleRepository 的 Add 方法,我正在使用 IRepository 接口(interface),但我是模拟的新手,不知道如何从那里开
有人知道为什么 linq 查询在使用事件记录查询时比使用 simplerepository 查询慢大约 6 倍吗?下面的代码运行速度比我使用简单存储库查询数据时慢 6 倍。这段代码循环执行1000次
我如何使用 Subsonic 的 Find方法来搜索字段包含“null”值的行。为了便于讨论,我们假设我有一个名为“Visit”的 C# 类,其中包含一个名为“SynchronizedOn”的可为空的
我是一名优秀的程序员,十分优秀!