Entity Framework 4.0怎么直接执行sql查询语句

民工_小牛 2011-06-29 10:46:46
sql命令是针对oracle数据库的,,可以直接调用entities中的方法执行sql么,

倒是看到一个ExecuteStoreQuery方法,但是不会用,不知道是不是这个方法

没分了,见谅
...全文
1540 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
民工_小牛 2012-07-20
  • 打赏
  • 举报
回复
再问一句,通过实体保存出错后,如果以后再保存其他的,那么先前出的错还会出,除非重启程序,显然这样的用户体验不好。

有没有一种方法当实体保存出错后,把实体做的更改删掉,我找半天找了个函数detectchanges,貌似不对
namhyuk 2011-07-06
  • 打赏
  • 举报
回复
要不你就把SQL查询封装在存储过程里,再通过EF访问这个存储过程。

民工_小牛 2011-07-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 caozhy 的回复:]

C# code
using (SchoolEntities context =
new SchoolEntities())
{
// The following three queries demonstrate
// three different ways of passing a parameter.
// The queries return a st……
[/Quote]

这个里面我也看到了,只是查询一个字段的情况,我需要的是复杂查询的结果,

最终没办法了,只能通过直接进行SQL查询了,绕过了实体,当然也破了系统实体的金身,哎

至于实体SQL,结合我的应用场景不是太适合
threenewbee 2011-06-30
  • 打赏
  • 举报
回复
using (SchoolEntities context =
new SchoolEntities())
{
// The following three queries demonstrate
// three different ways of passing a parameter.
// The queries return a string result type.

// Use the parameter substitution pattern.
foreach (string name in context.ExecuteStoreQuery<string>
("Select Name from Department where DepartmentID < {0}", 5))
{
Console.WriteLine(name);
}

// Use parameter syntax with object values.
foreach (string name in context.ExecuteStoreQuery<string>
("Select Name from Department where DepartmentID < @p0", 5))
{
Console.WriteLine(name);
}
// Use an explicit SqlParameter.
foreach (string name in context.ExecuteStoreQuery<string>
("Select Name from Department where DepartmentID < @p0",
new SqlParameter { ParameterName = "p0", Value = 5 }))
{
Console.WriteLine(name);
}
}

kingdom_0 2011-06-30
  • 打赏
  • 举报
回复
如果用hibernate,就使用HQL解决最方便。
  • 打赏
  • 举报
回复
ExecuteStoreQuery这个方法应该是执行存储过程的!
namhyuk 2011-06-29
  • 打赏
  • 举报
回复
用Entity SQL吧。虽然没用EF访问过Oracle,但原理上Entity SQL应该是数据库无关的。Entity SQL只是语法上像极了SQL,但实际上还是需要对应的LINQ Provider把它转换为具体数据库的native SQL语句。

8,492

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧