Entity framework core 如何使用Azure函数(计时器触发器)和Azure sql配置实体Famework核心?

Entity framework core 如何使用Azure函数(计时器触发器)和Azure sql配置实体Famework核心?,entity-framework-core,azure-functions,azure-sql-database,Entity Framework Core,Azure Functions,Azure Sql Database,实际上,我在Azure Sql中有一个数据库,在另一个Azure帐户中有一个Azure函数(计时器触发器)(与数据库不同)我已经使用了Core Entity framework来映射数据库,但当我想进行查询时,它不起作用,所以配置有问题。我尝试了很多,尝试了一些解决方案,但仍然无法解决这个问题。我正在上传代码,希望你能帮我。提前谢谢 功能1.cs: using System; using System.Data.SqlClient; using System.Threading.Tasks; u

实际上,我在Azure Sql中有一个数据库,在另一个Azure帐户中有一个Azure函数(计时器触发器)(与数据库不同)我已经使用了Core Entity framework来映射数据库,但当我想进行查询时,它不起作用,所以配置有问题。我尝试了很多,尝试了一些解决方案,但仍然无法解决这个问题。我正在上传代码,希望你能帮我。提前谢谢

功能1.cs

using System;
using System.Data.SqlClient;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Microsoft.Azure.Functions.Extensions;
using Microsoft.Net.Http;
using Microsoft.EntityFrameworkCore.SqlServer.Design;
using Microsoft.EntityFrameworkCore.SqlServer;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using Newtonsoft.Json;





namespace azuretosharepoint
{

    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task RunAsync([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
        {
            var azsh = new ProgettokpidatabaseContext();
            var listsharepoint = azsh.KpiTables.ToList();
            Console.WriteLine(listsharepoint);
                            
            
         }
    }
}
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Design;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;

#nullable disable

namespace azuretosharepoint
{
    public partial class ProgettokpidatabaseContext : DbContext
    {
        public ProgettokpidatabaseContext()
        {
        }

        public ProgettokpidatabaseContext(DbContextOptions<ProgettokpidatabaseContext> options)
            : base(options)
        {
        }

        public virtual DbSet<KpiTable> KpiTables { get; set; }
        public virtual DbSet<KptKpiTarget> KptKpiTargets { get; set; }
        public virtual DbSet<KpvKpiValue> KpvKpiValues { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer(Environment.GetEnvironmentVariable("sqlconnectionstring"));
               //#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                //optionsBuilder.UseSqlServer("Server=tcp:progetto-kpi.database.windows.net,1433;Initial Catalog=progetto-kpi-database;Persist Security Info=False;User ID=progetto-kpi;Password=**********;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");

            modelBuilder.Entity<KpiTable>(entity =>
            {
                entity.HasKey(e => e.KpiId);

                entity.ToTable("KPI_table");

                entity.Property(e => e.KpiId)
                    .ValueGeneratedNever()
                    .HasColumnName("KPI_ID");

                entity.Property(e => e.KpiBusinessArea)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("KPI_Business_Area");

                entity.Property(e => e.KpiDescription)
                    .HasMaxLength(250)
                    .HasColumnName("KPI_Description");

                entity.Property(e => e.KpiDoi)
                    .HasColumnType("datetime")
                    .HasColumnName("KPI_DOI")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpiDou)
                    .HasColumnType("datetime")
                    .HasColumnName("KPI_DOU")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpiFrequency)
                    .HasMaxLength(10)
                    .HasColumnName("KPI_Frequency");

                entity.Property(e => e.KpiManual).HasColumnName("KPI_Manual");

                entity.Property(e => e.KpiName)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("KPI_Name");
            });

            modelBuilder.Entity<KptKpiTarget>(entity =>
            {
                entity.HasKey(e => e.KptId)
                    .HasName("PK_KPT_table");

                entity.ToTable("KPT_KPI_Targets");

                entity.Property(e => e.KptId)
                    .ValueGeneratedNever()
                    .HasColumnName("KPT_ID");

                entity.Property(e => e.KptDate)
                    .HasColumnType("date")
                    .HasColumnName("KPT_Date");

                entity.Property(e => e.KptDoi)
                    .HasColumnType("datetime")
                    .HasColumnName("KPT_DOI")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KptDou)
                    .HasColumnType("datetime")
                    .HasColumnName("KPT_DOU")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KptKpiId).HasColumnName("KPT_KPI_ID");

                entity.Property(e => e.KptTarget)
                    .HasColumnType("decimal(18, 2)")
                    .HasColumnName("KPT_Target");

                entity.HasOne(d => d.KptKpi)
                    .WithMany(p => p.KptKpiTargets)
                    .HasForeignKey(d => d.KptKpiId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__KPT_KPI_T__KPT_K__2FCF1A8A");
            });

            modelBuilder.Entity<KpvKpiValue>(entity =>
            {
                entity.HasKey(e => e.KpvId)
                    .HasName("PK_KPV_table");

                entity.ToTable("KPV_KPI_Values");

                entity.Property(e => e.KpvId)
                    .ValueGeneratedNever()
                    .HasColumnName("KPV_ID");

                entity.Property(e => e.KpvDate)
                    .HasColumnType("date")
                    .HasColumnName("KPV_Date");

                entity.Property(e => e.KpvDoi)
                    .HasColumnType("datetime")
                    .HasColumnName("KPV_DOI")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpvDou)
                    .HasColumnType("datetime")
                    .HasColumnName("KPV_DOU")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpvKpiId).HasColumnName("KPV_KPI_ID");

                entity.Property(e => e.KpvValue)
                    .HasColumnType("decimal(18, 2)")
                    .HasColumnName("KPV_Value");

                entity.HasOne(d => d.KpvKpi)
                    .WithMany(p => p.KpvKpiValues)
                    .HasForeignKey(d => d.KpvKpiId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__KPV_KPI_V__KPV_K__3587F3E0");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
{
  "IsEncrypted": false,
  "AzureWebJobsStorage": "UseDevelopmentStorage=true",
  "FUNCTIONS_WORKER_RUNTIME": "dotnet",
  "Values": {
    "sqlconnectionstring": "Server=tcp:progetto-kpi.database.windows.net,1433;Initial Catalog=progetto-kpi-database;Persist Security Info=False;User ID=progetto-kpi;Password=*********;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
    "ProviderName": "System.Data.SqlClient"


  }
}
Azure Functions Core Tools
Core Tools Version:       3.0.3568 Commit hash: e30a0ede85fd498199c28ad699ab2548593f759b  (64-bit)
Function Runtime Version: 3.0.15828.0

Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]
Missing value for AzureWebJobsStorage in local.settings.json. This is required for all triggers other than httptrigger, kafkatrigger, rabbitmqtrigger, orchestrationTrigger, activityTrigger, entityTrigger. You can run 'func azure functionapp fetch-app-settings <functionAppName>' or specify a connection string in local.settings.json.
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <UserSecretsId>4e8db286-9c45-4574-b556-eb0a04ac345e</UserSecretsId>
    <OutputType>Library</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Dapper" Version="2.0.90" />
    <PackageReference Include="Dapper.Contrib" Version="2.0.78" />
    <PackageReference Include="Dapper.FluentMap" Version="2.0.0" />
    <PackageReference Include="Dapper.SimpleCRUD" Version="2.3.0" />
    <PackageReference Include="EntityFramework" Version="6.4.4" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.18.0-beta1" />
    <PackageReference Include="Microsoft.AspNetCore.AzureKeyVault.HostingStartup" Version="2.0.4" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.10" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.12" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0-preview.4.21253.7" />
    <PackageReference Include="System.Data.Common" Version="4.3.0" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
    <PackageReference Include="System.IO" Version="4.3.0" />
    <PackageReference Include="System.Linq" Version="4.3.0" />
    <PackageReference Include="System.Runtime" Version="4.3.1" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
  </ItemGroup>
</Project>
progettokpidatabaseContext.cs

using System;
using System.Data.SqlClient;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Microsoft.Azure.Functions.Extensions;
using Microsoft.Net.Http;
using Microsoft.EntityFrameworkCore.SqlServer.Design;
using Microsoft.EntityFrameworkCore.SqlServer;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using Newtonsoft.Json;





namespace azuretosharepoint
{

    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task RunAsync([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
        {
            var azsh = new ProgettokpidatabaseContext();
            var listsharepoint = azsh.KpiTables.ToList();
            Console.WriteLine(listsharepoint);
                            
            
         }
    }
}
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Design;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;

#nullable disable

namespace azuretosharepoint
{
    public partial class ProgettokpidatabaseContext : DbContext
    {
        public ProgettokpidatabaseContext()
        {
        }

        public ProgettokpidatabaseContext(DbContextOptions<ProgettokpidatabaseContext> options)
            : base(options)
        {
        }

        public virtual DbSet<KpiTable> KpiTables { get; set; }
        public virtual DbSet<KptKpiTarget> KptKpiTargets { get; set; }
        public virtual DbSet<KpvKpiValue> KpvKpiValues { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer(Environment.GetEnvironmentVariable("sqlconnectionstring"));
               //#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                //optionsBuilder.UseSqlServer("Server=tcp:progetto-kpi.database.windows.net,1433;Initial Catalog=progetto-kpi-database;Persist Security Info=False;User ID=progetto-kpi;Password=**********;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");

            modelBuilder.Entity<KpiTable>(entity =>
            {
                entity.HasKey(e => e.KpiId);

                entity.ToTable("KPI_table");

                entity.Property(e => e.KpiId)
                    .ValueGeneratedNever()
                    .HasColumnName("KPI_ID");

                entity.Property(e => e.KpiBusinessArea)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("KPI_Business_Area");

                entity.Property(e => e.KpiDescription)
                    .HasMaxLength(250)
                    .HasColumnName("KPI_Description");

                entity.Property(e => e.KpiDoi)
                    .HasColumnType("datetime")
                    .HasColumnName("KPI_DOI")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpiDou)
                    .HasColumnType("datetime")
                    .HasColumnName("KPI_DOU")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpiFrequency)
                    .HasMaxLength(10)
                    .HasColumnName("KPI_Frequency");

                entity.Property(e => e.KpiManual).HasColumnName("KPI_Manual");

                entity.Property(e => e.KpiName)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("KPI_Name");
            });

            modelBuilder.Entity<KptKpiTarget>(entity =>
            {
                entity.HasKey(e => e.KptId)
                    .HasName("PK_KPT_table");

                entity.ToTable("KPT_KPI_Targets");

                entity.Property(e => e.KptId)
                    .ValueGeneratedNever()
                    .HasColumnName("KPT_ID");

                entity.Property(e => e.KptDate)
                    .HasColumnType("date")
                    .HasColumnName("KPT_Date");

                entity.Property(e => e.KptDoi)
                    .HasColumnType("datetime")
                    .HasColumnName("KPT_DOI")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KptDou)
                    .HasColumnType("datetime")
                    .HasColumnName("KPT_DOU")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KptKpiId).HasColumnName("KPT_KPI_ID");

                entity.Property(e => e.KptTarget)
                    .HasColumnType("decimal(18, 2)")
                    .HasColumnName("KPT_Target");

                entity.HasOne(d => d.KptKpi)
                    .WithMany(p => p.KptKpiTargets)
                    .HasForeignKey(d => d.KptKpiId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__KPT_KPI_T__KPT_K__2FCF1A8A");
            });

            modelBuilder.Entity<KpvKpiValue>(entity =>
            {
                entity.HasKey(e => e.KpvId)
                    .HasName("PK_KPV_table");

                entity.ToTable("KPV_KPI_Values");

                entity.Property(e => e.KpvId)
                    .ValueGeneratedNever()
                    .HasColumnName("KPV_ID");

                entity.Property(e => e.KpvDate)
                    .HasColumnType("date")
                    .HasColumnName("KPV_Date");

                entity.Property(e => e.KpvDoi)
                    .HasColumnType("datetime")
                    .HasColumnName("KPV_DOI")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpvDou)
                    .HasColumnType("datetime")
                    .HasColumnName("KPV_DOU")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpvKpiId).HasColumnName("KPV_KPI_ID");

                entity.Property(e => e.KpvValue)
                    .HasColumnType("decimal(18, 2)")
                    .HasColumnName("KPV_Value");

                entity.HasOne(d => d.KpvKpi)
                    .WithMany(p => p.KpvKpiValues)
                    .HasForeignKey(d => d.KpvKpiId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__KPV_KPI_V__KPV_K__3587F3E0");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
{
  "IsEncrypted": false,
  "AzureWebJobsStorage": "UseDevelopmentStorage=true",
  "FUNCTIONS_WORKER_RUNTIME": "dotnet",
  "Values": {
    "sqlconnectionstring": "Server=tcp:progetto-kpi.database.windows.net,1433;Initial Catalog=progetto-kpi-database;Persist Security Info=False;User ID=progetto-kpi;Password=*********;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
    "ProviderName": "System.Data.SqlClient"


  }
}
Azure Functions Core Tools
Core Tools Version:       3.0.3568 Commit hash: e30a0ede85fd498199c28ad699ab2548593f759b  (64-bit)
Function Runtime Version: 3.0.15828.0

Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]
Missing value for AzureWebJobsStorage in local.settings.json. This is required for all triggers other than httptrigger, kafkatrigger, rabbitmqtrigger, orchestrationTrigger, activityTrigger, entityTrigger. You can run 'func azure functionapp fetch-app-settings <functionAppName>' or specify a connection string in local.settings.json.
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <UserSecretsId>4e8db286-9c45-4574-b556-eb0a04ac345e</UserSecretsId>
    <OutputType>Library</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Dapper" Version="2.0.90" />
    <PackageReference Include="Dapper.Contrib" Version="2.0.78" />
    <PackageReference Include="Dapper.FluentMap" Version="2.0.0" />
    <PackageReference Include="Dapper.SimpleCRUD" Version="2.3.0" />
    <PackageReference Include="EntityFramework" Version="6.4.4" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.18.0-beta1" />
    <PackageReference Include="Microsoft.AspNetCore.AzureKeyVault.HostingStartup" Version="2.0.4" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.10" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.12" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0-preview.4.21253.7" />
    <PackageReference Include="System.Data.Common" Version="4.3.0" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
    <PackageReference Include="System.IO" Version="4.3.0" />
    <PackageReference Include="System.Linq" Version="4.3.0" />
    <PackageReference Include="System.Runtime" Version="4.3.1" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
  </ItemGroup>
</Project>
问题:

using System;
using System.Data.SqlClient;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Microsoft.Azure.Functions.Extensions;
using Microsoft.Net.Http;
using Microsoft.EntityFrameworkCore.SqlServer.Design;
using Microsoft.EntityFrameworkCore.SqlServer;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using Newtonsoft.Json;





namespace azuretosharepoint
{

    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task RunAsync([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
        {
            var azsh = new ProgettokpidatabaseContext();
            var listsharepoint = azsh.KpiTables.ToList();
            Console.WriteLine(listsharepoint);
                            
            
         }
    }
}
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Design;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;

#nullable disable

namespace azuretosharepoint
{
    public partial class ProgettokpidatabaseContext : DbContext
    {
        public ProgettokpidatabaseContext()
        {
        }

        public ProgettokpidatabaseContext(DbContextOptions<ProgettokpidatabaseContext> options)
            : base(options)
        {
        }

        public virtual DbSet<KpiTable> KpiTables { get; set; }
        public virtual DbSet<KptKpiTarget> KptKpiTargets { get; set; }
        public virtual DbSet<KpvKpiValue> KpvKpiValues { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer(Environment.GetEnvironmentVariable("sqlconnectionstring"));
               //#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                //optionsBuilder.UseSqlServer("Server=tcp:progetto-kpi.database.windows.net,1433;Initial Catalog=progetto-kpi-database;Persist Security Info=False;User ID=progetto-kpi;Password=**********;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");

            modelBuilder.Entity<KpiTable>(entity =>
            {
                entity.HasKey(e => e.KpiId);

                entity.ToTable("KPI_table");

                entity.Property(e => e.KpiId)
                    .ValueGeneratedNever()
                    .HasColumnName("KPI_ID");

                entity.Property(e => e.KpiBusinessArea)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("KPI_Business_Area");

                entity.Property(e => e.KpiDescription)
                    .HasMaxLength(250)
                    .HasColumnName("KPI_Description");

                entity.Property(e => e.KpiDoi)
                    .HasColumnType("datetime")
                    .HasColumnName("KPI_DOI")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpiDou)
                    .HasColumnType("datetime")
                    .HasColumnName("KPI_DOU")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpiFrequency)
                    .HasMaxLength(10)
                    .HasColumnName("KPI_Frequency");

                entity.Property(e => e.KpiManual).HasColumnName("KPI_Manual");

                entity.Property(e => e.KpiName)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("KPI_Name");
            });

            modelBuilder.Entity<KptKpiTarget>(entity =>
            {
                entity.HasKey(e => e.KptId)
                    .HasName("PK_KPT_table");

                entity.ToTable("KPT_KPI_Targets");

                entity.Property(e => e.KptId)
                    .ValueGeneratedNever()
                    .HasColumnName("KPT_ID");

                entity.Property(e => e.KptDate)
                    .HasColumnType("date")
                    .HasColumnName("KPT_Date");

                entity.Property(e => e.KptDoi)
                    .HasColumnType("datetime")
                    .HasColumnName("KPT_DOI")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KptDou)
                    .HasColumnType("datetime")
                    .HasColumnName("KPT_DOU")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KptKpiId).HasColumnName("KPT_KPI_ID");

                entity.Property(e => e.KptTarget)
                    .HasColumnType("decimal(18, 2)")
                    .HasColumnName("KPT_Target");

                entity.HasOne(d => d.KptKpi)
                    .WithMany(p => p.KptKpiTargets)
                    .HasForeignKey(d => d.KptKpiId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__KPT_KPI_T__KPT_K__2FCF1A8A");
            });

            modelBuilder.Entity<KpvKpiValue>(entity =>
            {
                entity.HasKey(e => e.KpvId)
                    .HasName("PK_KPV_table");

                entity.ToTable("KPV_KPI_Values");

                entity.Property(e => e.KpvId)
                    .ValueGeneratedNever()
                    .HasColumnName("KPV_ID");

                entity.Property(e => e.KpvDate)
                    .HasColumnType("date")
                    .HasColumnName("KPV_Date");

                entity.Property(e => e.KpvDoi)
                    .HasColumnType("datetime")
                    .HasColumnName("KPV_DOI")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpvDou)
                    .HasColumnType("datetime")
                    .HasColumnName("KPV_DOU")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpvKpiId).HasColumnName("KPV_KPI_ID");

                entity.Property(e => e.KpvValue)
                    .HasColumnType("decimal(18, 2)")
                    .HasColumnName("KPV_Value");

                entity.HasOne(d => d.KpvKpi)
                    .WithMany(p => p.KpvKpiValues)
                    .HasForeignKey(d => d.KpvKpiId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__KPV_KPI_V__KPV_K__3587F3E0");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
{
  "IsEncrypted": false,
  "AzureWebJobsStorage": "UseDevelopmentStorage=true",
  "FUNCTIONS_WORKER_RUNTIME": "dotnet",
  "Values": {
    "sqlconnectionstring": "Server=tcp:progetto-kpi.database.windows.net,1433;Initial Catalog=progetto-kpi-database;Persist Security Info=False;User ID=progetto-kpi;Password=*********;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
    "ProviderName": "System.Data.SqlClient"


  }
}
Azure Functions Core Tools
Core Tools Version:       3.0.3568 Commit hash: e30a0ede85fd498199c28ad699ab2548593f759b  (64-bit)
Function Runtime Version: 3.0.15828.0

Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]
Missing value for AzureWebJobsStorage in local.settings.json. This is required for all triggers other than httptrigger, kafkatrigger, rabbitmqtrigger, orchestrationTrigger, activityTrigger, entityTrigger. You can run 'func azure functionapp fetch-app-settings <functionAppName>' or specify a connection string in local.settings.json.
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <UserSecretsId>4e8db286-9c45-4574-b556-eb0a04ac345e</UserSecretsId>
    <OutputType>Library</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Dapper" Version="2.0.90" />
    <PackageReference Include="Dapper.Contrib" Version="2.0.78" />
    <PackageReference Include="Dapper.FluentMap" Version="2.0.0" />
    <PackageReference Include="Dapper.SimpleCRUD" Version="2.3.0" />
    <PackageReference Include="EntityFramework" Version="6.4.4" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.18.0-beta1" />
    <PackageReference Include="Microsoft.AspNetCore.AzureKeyVault.HostingStartup" Version="2.0.4" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.10" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.12" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0-preview.4.21253.7" />
    <PackageReference Include="System.Data.Common" Version="4.3.0" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
    <PackageReference Include="System.IO" Version="4.3.0" />
    <PackageReference Include="System.Linq" Version="4.3.0" />
    <PackageReference Include="System.Runtime" Version="4.3.1" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
  </ItemGroup>
</Project>
Azure功能核心工具
核心工具版本:3.0.3568提交哈希:e30a0ede85fd498199c28ad699ab2548593f759b(64位)
函数运行时版本:3.0.15828.0
无法从文件确定项目语言。请使用[-csharp,--javascript,--typescript,--java,--python,--powershell,--custom]之一
local.settings.json中缺少AzureWebJobsStorage的值。除httptrigger、kafkatrigger、rabbitmqtrigger、orchestrationTrigger、activityTrigger、entityTrigger之外的所有触发器都需要此选项。您可以运行“func azure functionapp fetch app settings”或在local.settings.json中指定连接字符串。
azuretosharepoint.csproj:

using System;
using System.Data.SqlClient;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Microsoft.Azure.Functions.Extensions;
using Microsoft.Net.Http;
using Microsoft.EntityFrameworkCore.SqlServer.Design;
using Microsoft.EntityFrameworkCore.SqlServer;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using Newtonsoft.Json;





namespace azuretosharepoint
{

    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task RunAsync([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
        {
            var azsh = new ProgettokpidatabaseContext();
            var listsharepoint = azsh.KpiTables.ToList();
            Console.WriteLine(listsharepoint);
                            
            
         }
    }
}
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Design;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;

#nullable disable

namespace azuretosharepoint
{
    public partial class ProgettokpidatabaseContext : DbContext
    {
        public ProgettokpidatabaseContext()
        {
        }

        public ProgettokpidatabaseContext(DbContextOptions<ProgettokpidatabaseContext> options)
            : base(options)
        {
        }

        public virtual DbSet<KpiTable> KpiTables { get; set; }
        public virtual DbSet<KptKpiTarget> KptKpiTargets { get; set; }
        public virtual DbSet<KpvKpiValue> KpvKpiValues { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer(Environment.GetEnvironmentVariable("sqlconnectionstring"));
               //#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                //optionsBuilder.UseSqlServer("Server=tcp:progetto-kpi.database.windows.net,1433;Initial Catalog=progetto-kpi-database;Persist Security Info=False;User ID=progetto-kpi;Password=**********;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");

            modelBuilder.Entity<KpiTable>(entity =>
            {
                entity.HasKey(e => e.KpiId);

                entity.ToTable("KPI_table");

                entity.Property(e => e.KpiId)
                    .ValueGeneratedNever()
                    .HasColumnName("KPI_ID");

                entity.Property(e => e.KpiBusinessArea)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("KPI_Business_Area");

                entity.Property(e => e.KpiDescription)
                    .HasMaxLength(250)
                    .HasColumnName("KPI_Description");

                entity.Property(e => e.KpiDoi)
                    .HasColumnType("datetime")
                    .HasColumnName("KPI_DOI")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpiDou)
                    .HasColumnType("datetime")
                    .HasColumnName("KPI_DOU")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpiFrequency)
                    .HasMaxLength(10)
                    .HasColumnName("KPI_Frequency");

                entity.Property(e => e.KpiManual).HasColumnName("KPI_Manual");

                entity.Property(e => e.KpiName)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("KPI_Name");
            });

            modelBuilder.Entity<KptKpiTarget>(entity =>
            {
                entity.HasKey(e => e.KptId)
                    .HasName("PK_KPT_table");

                entity.ToTable("KPT_KPI_Targets");

                entity.Property(e => e.KptId)
                    .ValueGeneratedNever()
                    .HasColumnName("KPT_ID");

                entity.Property(e => e.KptDate)
                    .HasColumnType("date")
                    .HasColumnName("KPT_Date");

                entity.Property(e => e.KptDoi)
                    .HasColumnType("datetime")
                    .HasColumnName("KPT_DOI")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KptDou)
                    .HasColumnType("datetime")
                    .HasColumnName("KPT_DOU")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KptKpiId).HasColumnName("KPT_KPI_ID");

                entity.Property(e => e.KptTarget)
                    .HasColumnType("decimal(18, 2)")
                    .HasColumnName("KPT_Target");

                entity.HasOne(d => d.KptKpi)
                    .WithMany(p => p.KptKpiTargets)
                    .HasForeignKey(d => d.KptKpiId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__KPT_KPI_T__KPT_K__2FCF1A8A");
            });

            modelBuilder.Entity<KpvKpiValue>(entity =>
            {
                entity.HasKey(e => e.KpvId)
                    .HasName("PK_KPV_table");

                entity.ToTable("KPV_KPI_Values");

                entity.Property(e => e.KpvId)
                    .ValueGeneratedNever()
                    .HasColumnName("KPV_ID");

                entity.Property(e => e.KpvDate)
                    .HasColumnType("date")
                    .HasColumnName("KPV_Date");

                entity.Property(e => e.KpvDoi)
                    .HasColumnType("datetime")
                    .HasColumnName("KPV_DOI")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpvDou)
                    .HasColumnType("datetime")
                    .HasColumnName("KPV_DOU")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.KpvKpiId).HasColumnName("KPV_KPI_ID");

                entity.Property(e => e.KpvValue)
                    .HasColumnType("decimal(18, 2)")
                    .HasColumnName("KPV_Value");

                entity.HasOne(d => d.KpvKpi)
                    .WithMany(p => p.KpvKpiValues)
                    .HasForeignKey(d => d.KpvKpiId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__KPV_KPI_V__KPV_K__3587F3E0");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
{
  "IsEncrypted": false,
  "AzureWebJobsStorage": "UseDevelopmentStorage=true",
  "FUNCTIONS_WORKER_RUNTIME": "dotnet",
  "Values": {
    "sqlconnectionstring": "Server=tcp:progetto-kpi.database.windows.net,1433;Initial Catalog=progetto-kpi-database;Persist Security Info=False;User ID=progetto-kpi;Password=*********;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
    "ProviderName": "System.Data.SqlClient"


  }
}
Azure Functions Core Tools
Core Tools Version:       3.0.3568 Commit hash: e30a0ede85fd498199c28ad699ab2548593f759b  (64-bit)
Function Runtime Version: 3.0.15828.0

Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]
Missing value for AzureWebJobsStorage in local.settings.json. This is required for all triggers other than httptrigger, kafkatrigger, rabbitmqtrigger, orchestrationTrigger, activityTrigger, entityTrigger. You can run 'func azure functionapp fetch-app-settings <functionAppName>' or specify a connection string in local.settings.json.
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <UserSecretsId>4e8db286-9c45-4574-b556-eb0a04ac345e</UserSecretsId>
    <OutputType>Library</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Dapper" Version="2.0.90" />
    <PackageReference Include="Dapper.Contrib" Version="2.0.78" />
    <PackageReference Include="Dapper.FluentMap" Version="2.0.0" />
    <PackageReference Include="Dapper.SimpleCRUD" Version="2.3.0" />
    <PackageReference Include="EntityFramework" Version="6.4.4" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.18.0-beta1" />
    <PackageReference Include="Microsoft.AspNetCore.AzureKeyVault.HostingStartup" Version="2.0.4" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.10" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.12" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0-preview.4.21253.7" />
    <PackageReference Include="System.Data.Common" Version="4.3.0" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
    <PackageReference Include="System.IO" Version="4.3.0" />
    <PackageReference Include="System.Linq" Version="4.3.0" />
    <PackageReference Include="System.Runtime" Version="4.3.1" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
  </ItemGroup>
</Project>

netcoreapp3.1
v3
4e8db286-9c45-4574-b556-eb0a04ac345e
图书馆
全部的
运行时间;建设;本地人;内容文件;分析仪;可传递的
全部的
运行时间;建设;本地人;内容文件;分析仪;可传递的
保存最新
总是
从未

您的local.settings.json似乎格式不正确。尝试:

{
“IsEncrypted”:错误,
“价值观”:{
“AzureWebJobsStorage”:“UseDevelopmentStorage=true”,
“函数\u工作者\u运行时”:“dotnet”,
“sqlconnectionstring”:“YOURCONNECTIONSTRING”,
“ProviderName”:“我不使用此值-IN-MY-CONFIGS”
}
}
此外,您的连接字符串的密码已被清除。如果你从Azure门户的某些部分获取它,你就会得到它。你可能是故意这么做的,但如果你没有这样做-删除星号^

快速测试是本地函数配置问题还是代码问题的方法:

  • 打开新的GitBash提示符/其他终端
  • func init TestMe--dotnet
    光盘测试
    func new--name TestEndpoint--template“HTTP触发器”--authlevel“匿名”
    功能启动
    
    要创建测试计时器触发器,请执行以下操作:

    func new--name Timer--template“Timer trigger”
    
    此错误发生在本地主机或azure上?请尝试创建一个单独的新本地azure功能项目。VisualStudio代码对此进行了很好的扩展。浏览hello world教程,并验证您可以在本地使用一个简单的HTTP触发器函数。然后比较两个项目之间的配置。你在某个地方遗漏了一个设置。我试过了,一个全新的函数项目也有同样的问题吗?您已经运行了dotnet restore,是吗?结果是:从“HTTP触发器”模板成功创建了函数“TestEndpoint”。太棒了!尝试创建一个计时器触发器。如果可以的话,您至少可以将上一个项目中以前的代码复制到这个测试项目中,并从那里开始。有人可能会有一个更优雅的解决方案,但当我遇到障碍时,这种方法对我很有效:获得一个工作环境,验证基础知识,逐个添加功能。