Select some columns instead of select * with SubSonic 3

108 Views Asked by At

I'm using SubSonic 3 as my OR mapper in the project. My problem is that the query SubSonic generates for select and other operations is like:

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

And this would make select * from the entity, but I have to select only Id and Title from the table. I don't have permission to select * on the table

1

There are 1 best solutions below

0
Kevin On

There isn't much to go off of and you probably solved this problem already but just in case someone else has the same question, here's my 2 cents.

If you just wanted to select Id and Title you could do one of the following.

I'm guessing you're using 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();

If you're using AdvancedTemplate, then you could do

//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();