I have a table with below columns.
CREATE TABLE [dbo].[tbl_QuizQue](
[id] [int] IDENTITY(1,1) NOT NULL,
[question] [nvarchar](max) NOT NULL,
[opt1] [nvarchar](50) NOT NULL,
[opt2] [nvarchar](50) NOT NULL,
[opt3] [nvarchar](50) NOT NULL,
[ans] [nvarchar](50) NOT NULL
)
I am trying to get a random record from this table, but only specific columns Like id, question, opt1, opt2, opt3. Present I am getting random record but it is fetching all columns. I tried below code for fetching a record with specific columns
dbUserEntities obj = new dbUserEntities();
// GET api/values
public IEnumerable<tbl_QuizQue> Get()
{
var result = obj.tbl_QuizQue.OrderBy(r => Guid.NewGuid()).Select(o => new { o.id, o.question, o.opt1, o.opt2, o.opt3 });
return result;
}
Here, i am getting below error while return result;
Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' to
'System.Collections.Generic.IEnumerable<studentQuiz.tbl_QuizQue>'. An explicit conversion exists (are you missing a cast?)
Help me where I am doing wrong.