tags:

views:

36

answers:

1

Hello,

I'm using Visual Studio 2010 Express with Framework 4.0 and if I am correct, it comes with Entity Framework 4.

My ObjectContext is defined as:

public partial class CreaturesEntities : global::System.Data.Objects.ObjectContext

I tried to use ExecuteStoreQuery :

using System.Data.Objects;
using System.Data.Entity;
[...]
context = new CreaturesEntities();
string query = "select type, min(value) value from saving_throw where ";
string conditions = "(classe_id=" + classe_id + " and level=" + level1 + ")";
if (classe.subclass1_id != null)
    conditions += " or (classe_id=" + classe.subclass1_id + " and level=" + level1 + ")";
if (classe.subclass2_id != null)
    conditions += " or (classe_id=" + classe.subclass2_id + " and level=" + level2 + ")";
if (classe.subclass3_id != null)
    conditions += " or (classe_id=" + classe.subclass3_id + " and level=" + level3 + ")";
query = query + conditions + " group by type";
var q = context.ExecuteStoreQuery<SimpleNumber>(query);
// SimpleNumber is a class with an int property, I suppose ExecuteStoreQuery<Integer> wouldn't work?

When I type "context.", I can't find ExecuteStoreQuery in context menu, which means it is not available for whatever reasons. I can't find anything about a missing method in ObjectContext. Does this mean that Visual Studio 2010 Express doesn't include Entity Framework 4 ? Because standard edition does, and it would be strange that express edition uses an older version.

Of course, I could use a classic DataReader but ExecuteStoreQuery is a lot better.

Any idea?

Edit : I change query to the real one to explain why ExecuteStoreQuery is sometimes easier for complex query (at least for beginners in LINQ To Entities)

A: 

Why not use LINQ to Entities instead?

context.Spells.Where(s => s.ID.Equals(1));
Johan Olsson
I edited my original query for the real one. It's complicated enough to justify the use of ExecuteStoreQuery. And even if I could do it in LINQ to Entities, I just wonder why ExecuteStoreQuery is not present on my ObjectContext
Arnaud
OK, but I would still use LINQ to Entities and write my own custom LINQ extension methods.
Johan Olsson
I've used LINQ to Entities finally, better than coding an extension method that should already exists. As I must hurry in my dev, I mark this question as answered, even it doesn't really the one I expected.
Arnaud