1

I am trying to query something like this:

var values = new Entities().result.SqlQuery( 
"select distinct     
i.item_type_id,     
Min(value) over (partition by i.item_type_id) as min,     
Max(value) over (partition by i.item_type_id) as max,     
Avg(value) over (partition by i.item_type_id) as avg    
from items i   
inner join packages p on p.id = i.package_id " 
WHERE ... ").ToList();

First I tried var values = new Entities().item.SqlQuery(...) but the result has nothing to do with item, item has different properties from the result of this query.

Than I created result object:

public partial class rolling_table
{
    public int item_type_id { get; set; }
    public int min { get; set; }
    public int max { get; set; }
    public int avg { get; set; }
}

and run var values = new Entities().result.SqlQuery()

But it is complaining that

The entity type result is not part of the model for the current context.

I guess it thinks result is a table in the database, however it is not.

How can I query custom type, not persistent objects ?

thanks

1 Answer 1

1

You can use the SqlQuery method on the Database object.

var values = context.Database.SqlQuery<rolling_table>("your_query").ToList();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.