问题
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