Click here to Skip to main content
15,944,401 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

I am learning Entity Framework 4 from book.

And I try to make some Query with Entity SQL like this :

C#
using (var context = new BAEntities())
{
    string str = "SELECT VALUE c " +
                 "FROM BAEntities.Contacts " +
                 "AS c " +
                 "where c IS NOT OF(BAModel.Customer)";

    ObjectQuery<Contact> qry = context.CreateQuery<Contact>(str);

    Console.WriteLine(qry.Count());
}


My query purpose is to take all Objects of Contact Type but not of Customer Type.
Where, Customer inherits from Contact

And I got the following error :


Type 'BAModel.Customer' could not be found. Make sure that the required schemas are loaded and that the namespaces are imported correctly. Near type name, line 1, column 64.

But, If I do query with LINQ to Entities like this :
ObjectQuery<Contact> qry = context.Contacts.Where(c => !(c is Customer));

then program can Run correctly.

So, why in Entity SQL BAModel.Customer is not found, whereas I ran the code within the same project in which the model is located.

Please help me in this regard.

Thanks in Advance.
Posted
Updated 8-Jun-11 4:28am
v19
Comments
OriginalGriff 8-Jun-11 10:06am    
Stop bumping this question: If anyone is going to answer they will answer. Bumping it continually is more likely to get you down-votes than answers.

I had the same issue... But in my case somehow the setting for Code Generation Strategy (one of the properties on the Model) had been set to "NONE" by default instead of "Default"... once I had changed the setting everything started to work.
 
Share this answer
 
Try using namespace-qualified names for types (i.e. MyNamespace.BAModel.Customer instead of BAModel.Customer).
 
Share this answer
 
Comments
adaapanya 8-Jun-11 12:30pm    
BAModel is the namespace of the Model.

Which namespace should I use?
dasblinkenlight 8-Jun-11 13:15pm    
Run Console.WriteLine(typeof(Customer).FullName) and use what's printed in your IS NOT OF(...) statement. I tried a query of the same structure on my EDM (using unqualified Contacts instead of BAEntities.Contacts), and I got the expected results back.
adaapanya 9-Jun-11 0:17am    
Thanks man.

My mistake is I use the namespace of the Model (ConceptualModel).
It turns out I must use the namespace of classes that was generated from Model (the namespace of classes within Model1.Designer.cs).
So, the fullname of the Customer in the model is : BAModel.Customer
and the fullname of the Customer class in the Model1.Designer.cs is : BAGA.Customer

Once again, Thanks for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900