【问题标题】:Select some columns instead of select * with SubSonic 3使用 SubSonic 3 选择一些列而不是选择 *
【发布时间】:2015-09-28 08:44:20
【问题描述】:

我在项目中使用 SubSonic 3 作为我的 OR 映射器。我的问题是 SubSonic 为select 和其他操作生成的查询是这样的:

var repo = GetRepo();
var results = repo.GetAll();

这将使实体中的select *,但我必须从表中仅选择IdTitle。我没有权限在桌子上select *

【问题讨论】:

    标签: subsonic3


    【解决方案1】:

    没什么可做的,你可能已经解决了这个问题,但万一其他人有同样的问题,这是我的 2 美分。

    如果您只想选择 IdTitle,您可以执行以下操作之一。

    我猜你正在使用 ActiveRecord。

    //results in a list of anonymous objects with Id and Title
    var results = (from r in YourTable.All() select new { Id = r.Id, Title = r.Title }).ToList();
    

    如果您使用的是 AdvancedTemplate,那么您可以这样做

    //create an instance of the db schema
    var repo = new SubSonic.AdvancedTemplate.YourDatabase();
    
    //results in a list of anonymous objects with Id and Title
    var results = (from r in repo.YourTable select new { Id = r.Id, Title = r.Title }).ToList();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-12
      • 2013-01-23
      • 2015-01-01
      相关资源
      最近更新 更多