EFCodeFirst CTP 5 不会使用任何记录填充模型 - 但查询运行良好
我将 EFCodeFirst 包与 MVCMusicStore 示例应用程序一起使用。
当我使用 SQL Express 数据库时,一切工作正常。但是,在 SQL Server 2008 中创建数据库并更新连接字符串后,我的所有查询都返回 0 条记录。 SQL Profiler 显示查询正在运行,我可以将查询复制到 SSMS 中,它会返回行。
这是一个查询和我的连接字符串:
var Genres = storeDb.Genres.ToList(); (返回计数为 0)
add name="MusicStoreEntities" connectionString="Data Source=.;initial Catalog=MvcMovieStore;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"providerName="System.Data.SqlClient"
任何想法对这种行为?它显然连接到数据库并执行我可以在 SQL Profiler 中看到的查询。
I'm using the EFCodeFirst package with the MVCMusicStore sample application.
Everything worked fine when I was using the SQL Express database. However, after creating the DB in SQL Server 2008 and updating the connection string, all my queries return 0 records. SQL Profiler shows that the queries run, and I can copy the query into SSMS and it returns rows.
Here's a query and my connection string:
var genres = storeDb.Genres.ToList(); (returns a count of 0)
add name="MusicStoreEntities" connectionString="Data Source=.;initial catalog=MvcMovieStore;integrated security=True;multipleactiveresultsets=True;App=EntityFramework" providerName="System.Data.SqlClient"
Any thoughts on this behavior? It obviously connects to the database and executes the query which I can see in SQL Profiler.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果查询在 SSMS 中运行并返回行,但您的应用程序中没有返回行,则一定是您的应用程序未针对同一个数据库实例运行。从 SQL CE 迁移到 Express 时,我遇到了完全相同的情况。
我最终所做的是使用服务器选项卡从应用程序连接到数据库,然后复制连接字符串。
If the query runs in SSMS and returns rows, but no rows are returned in your app, it must be that your app is not working against the same DB instance. I had the exact same situation when moving from SQL CE to Express.
What i ended up doing was connecting to the DB from the application, using the servers tab, and then copying the connection string.
尝试输入机器名称作为数据源...数据源=MYMACHINE
Try putting in the name of the machine as for Data Source ... Data Source=MYMACHINE