Selecting a subset of data in ServiceStack.OrmLite

我们两清 提交于 2019-12-24 03:26:06

问题


Is there any way to return a subset of a table in ServiceStack.OrmLite?
Something like:

public class MyStuff
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public byte[] Data { get; set; } // Some large blob, which is not desired in the list
}

var somestuff = db.Select<MyStuff>(x => new { Id = x.Id, Name = x.Name });

I am really hoping to avoid manual stuff, like "select blabla from somewhere"...


回答1:


I had that exact same problem. Here is what I did:

public class MyStuff
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public byte[] Data { get; set; } 
}

var somestuff = Db.Select<MyStuff>(p => p.Select(x => new { x.Id, x.Name }));

The only changes made, to what you did above, were done to the Db.Select.




回答2:


Create a class for your basic information and set an alias.

[Alias("MyStuff")]
public class MyBasicStuff
{
    public Guid Id { get;set; }
    public string Name { get; set; }
}

var basicStuff = db.Select<MyBasicStuff>();


来源:https://stackoverflow.com/questions/16354147/selecting-a-subset-of-data-in-servicestack-ormlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!