实体SQL问题 [英] Problem with Entity SQL

查看:73
本文介绍了实体SQL问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在从书本中学习Entity Framework4.

我尝试使用Entity SQL进行一些查询,如下所示:

 使用( var  context =  new  BAEntities())
{
    字符串 str = "  +
                 "  +
                 "  +
                 " ;

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

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



我的查询目的是获取联系人类型的所有对象,而不是客户类型的所有对象.
客户从何处继承联系人

我收到以下错误:


找不到类型"BAModel.Customer".确保已加载所需的架构,并且正确导入了名称空间.类型名称附近,第1行,第64列.

但是,如果我使用LINQ查询这样的实体:

ObjectQuery<Contact> qry = context.Contacts.Where(c => !(c is Customer));


则程序可以正常运行.

因此,为什么在Entity SQL中找不到BAModel.Customer,却在模型所在的同一项目中运行代码.

请在这方面帮助我.

解决方案

尝试对类型使用命名空间限定的名称(即MyNamespace.BAModel.Customer而不是BAModel.Customer).


<我有相同的问题...但是就我而言,代码生成策略(模型上的属性之一)的设置默认情况下已设置为"NONE",而不是"Default".更改了设置,一切开始起作用.


Hi All,

I am learning Entity Framework 4 from book.

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

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.

解决方案

Try using namespace-qualified names for types (i.e. MyNamespace.BAModel.Customer instead of BAModel.Customer).


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.


这篇关于实体SQL问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆