C# 是否有与 ActiveRecord#find_by 等效的等效项?
我最初是一名 C# 开发人员(作为一种爱好),但最近我一直在深入研究 Ruby on Rails,并且非常喜欢它。现在我正在用 C# 构建一个应用程序,我想知道 C# 是否有任何集合实现可以匹配(或“半匹配”)ActiveRecord 的 find_by 方法。
我本质上要寻找的是一个包含矩形
的列表:
class Rectangle
{
public int Width { get; set; }
public int Height { get; set; }
public string Name { get; set; }
}
我可以在其中查询此列表并查找Height = 10
,Width = 20<的所有条目/code> 或
name = "Block"
。这是通过 ActiveRecord 进行类似于 Rectangle.find_by_name('Block') 的调用来完成的。我能想到的在 C# 中执行此操作的唯一方法是创建我自己的列表实现,并迭代每个项目,根据条件手动检查每个项目。我担心我会重新发明轮子(而且质量较差)。
我不一定要尝试匹配命名约定 find_by_...
,而是要具有该方法的功能。
非常感谢任何意见或建议。
I'm originally a C# developer (as a hobby), but as of late I have been digging into Ruby on Rails and really enjoying it. Right now I am building an application in C#, and I was wondering if there is any collection implementation for C# that could match (or "semi-match") the find_by method of ActiveRecord.
What I am essentially looking for is a list that would hold Rectangles
:
class Rectangle
{
public int Width { get; set; }
public int Height { get; set; }
public string Name { get; set; }
}
Where I could query this list and find all entries with Height = 10
, Width = 20
, or name = "Block"
. This was done with ActiveRecord by doing a call similar to Rectangle.find_by_name('Block')
. The only way I can think of doing this in C# is to create my own list implementation and iterate through each item manually checking each item against the criteria. I fear I would be reinventing the wheel (and one of poorer quality).
I am not necessarily trying to match the naming convention find_by_...
, but rather to have the functionality of the method.
Any input or suggestions is much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“Linq 方法”,即添加在 . NET 3.5 非常接近您正在寻找的东西。
The "Linq methods", namely Where, that were added in .NET 3.5 are pretty close to what you're looking for.