无法从MVC应用程序中的数据库(实体框架)中检索数据

时间:2018-08-21 18:29:53

标签: c# asp.net asp.net-mvc entity-framework

我正在学习ASP.NET MVC(实体框架)。我创建了一个新项目,为现有数据库添加了模型,并在Web.config中添加了连接字符串。我已连接到数据库(我知道这是因为我能够通过服务器资源管理器查看表和数据)。我遇到的问题是,但是当我通过VS中的代码从数据库查询(lambda表达式)表时,没有任何结果,没有返回行,count等于零,但是表中有数据。我不在乎问题所在,不胜感激。

<!--Connection String(Web Config)-->
<section name="entityFramework" 
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, 
EntityFramework, Version=6.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>

<connectionStrings>
<!--<add name="PIS" connectionString="Data Source=Orgsysdev;Initial 
Catalog=ANPIS;persist security info=True;user 
id=pisuser;password=pispassword;MultipleActiveResultSets=True;" 
providerName="System.Data.SqlClient" />-->
</connectionStrings>

<!--DbContent Class(PISDb)-->  
namespace PISApp.Models
{
public class PIS: DbContext
{
    public PIS()
        : base("name=PIS")
    {
    }
    public virtual DbSet<Cultivation> CultivationTable { get; set; }
    public virtual DbSet<CultivationList> CultivationList { get; set; }
    public virtual DbSet<BlockList> BlockList { get; set; }
    public virtual DbSet<Condition> Condition { get; set; }
    }
    }

  <!--Entire Web Config -->
 <?xml version="1.0" encoding="utf-8"?>
 <!--
 For more information on how to configure your ASP.NET application, please 
 visit
 http://go.microsoft.com/fwlink/?LinkId=301880
 -->
 <configuration>
 <configSections>
 <!-- For more information on Entity Framework configuration, visit 
 http://go.microsoft.com/fwlink/?LinkID=237468 -->
 <section name="entityFramework" 
 type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, 
 EntityFramework, Version=6.0.0.0, Culture=neutral, 
 PublicKeyToken=b77a5c561934e089" requirePermission="false" />
 </configSections>
 <connectionStrings>
 <!--<add name="PIS" connectionString="Data Source=Orgsysdev;Initial 
 Catalog=ANPIS;persist security info=True;user 
 id=pisuser;password=pispassword;MultipleActiveResultSets=True;" 
 providerName="System.Data.SqlClient" />-->
 </connectionStrings>
 <appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
  <add name="ApplicationInsightsWebTracking" 
type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, 
Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.webServer>
<modules>
  <remove name="FormsAuthentication" />
  <remove name="ApplicationInsightsWebTracking" />
  <add name="ApplicationInsightsWebTracking" 
 type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, 
 Microsoft.AI.Web" preCondition="managedHandler" />
 </modules>
 <validation validateIntegratedModeConfiguration="false" />
 </system.webServer>
 <runtime>
 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security" 
  publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security.OAuth" 
  publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security.Cookies" 
  publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin" 
  publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" culture="neutral" 
  publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Optimization" 
  publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" 
  newVersion="1.5.2.14234" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" 
  publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" 
  publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" 
  publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>
   </assemblyBinding>
  </runtime>
  <entityFramework>
  <defaultConnectionFactory 
  type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, 
  EntityFramework">
  <parameters>
    <parameter value="mssqllocaldb" />
  </parameters>
   </defaultConnectionFactory>
  <providers>
  <provider invariantName="System.Data.SqlClient" 
   type="System.Data.Entity.SqlServer.SqlProviderServices, 
   EntityFramework.SqlServer" />
   </providers>
   </entityFramework>
   <system.codedom>

   </system.codedom>
   </configuration>

0 个答案:

没有答案