Question

I can use following line of code to create a query that only returns objects of 'ActivityEntity' type....

var q = CreateObjectSet<EntityBase>("EntityBases").OfType<ActivityEntity>()

.. and running the query works as expected. But I want to actually create a query using the Entity SQL syntax and hence tried to convert the above to the following code...

string query = "SELECT it FROM OFTYPE(MyContext.EntityBases, MyNamespace.ActivityEntity) AS it";
var q = context.CreateQuery<DbDataRecord>(query.ToString(), new ObjectParameter[] { });

...except this gives the following error...

Type 'MyNamespace.ActivityEntity' could not be found. Make sure that the required schemas are loaded and that the namespaces are imported correctly.

...both sets of code are inside the same C# file and so there is no way there is an issue with the namespace because the strongly typed version of code works just fine. Any ideas how to go about resolving this issue?

NOTE:

Not sure if this makes a difference but the Entity Framework is setup with Code Generation Strategy of None and then I have build my own classes for use. But I have marked them with the EdmEntityTypeAttribute attribute.

Was it helpful?

Solution

The solution turns out that I needed to ensure that CreateObjectSet had been used before generating the Entity SQL. So before creating the Entity SQL I use the following code...

var q = CreateObjectSet<EntityBase>("EntityBases").OfType<ActivityEntity>();

but never actually use the generated 'q'. Just using this line ensures that the Entity Framework context knows about the existence of the EntityBases collection and its derived types.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top