Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HongWei tried to modified the Bot.Builder.Community.Storage.EntityFra… #507

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove('$(MSBuildThisFileDirectory)../', 'Bot.Builder.Community.sln'))\CommonTargets\library.shared.targets" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Description>Entity Framework based storage for bots created using Microsoft Bot Builder SDK.</Description>
<Authors>Bot Builder Community</Authors>
<Company>Bot Builder Community</Company>
<PackageLicenseUrl>https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/tree/master/libraries/Bot.Builder.Community.Storage.EntityFramework</PackageProjectUrl>
<Version>1.0.0</Version>
<PackageTags>bot framework, bot builder, azure bot service, storage</PackageTags>
<FileVersion>1.0.0</FileVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Bot.Builder" Version="$(Bot_Builder_Version)" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Bot.Builder" Version="4.17.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.10" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,62 +1,64 @@
using System;
using Bot.Builder.Community.Storage.EntityFramework;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bot.Builder.Community.Storage.EntityFramework
namespace Bot.Builder.Community.Storage.EntityFramework;

public class BotDataContext : DbContext
{
private string? _connectionString;

/// <summary>
/// DbContext for BotDataEntitys
/// Constructor for BotDataContext receiving connectionString
/// </summary>
public class BotDataContext : DbContext
/// <param name="connectionString">Connection string to use when configuring the options during <see cref="OnConfiguring"/></param>
public BotDataContext(string connectionString)
: base()
{
private string _connectionString;

/// <summary>
/// Constructor for BotDataContext receiving connectionString
/// </summary>
/// <param name="connectionString">Connection string to use when configuring the options during <see cref="OnConfiguring"/></param>
public BotDataContext(string connectionString)
: base()
if (string.IsNullOrEmpty(connectionString))
{
if (string.IsNullOrEmpty(connectionString))
{
throw new ArgumentNullException(nameof(connectionString));
}

_connectionString = connectionString;
throw new ArgumentNullException(nameof(connectionString));
}

/// <summary>
/// Constructor for BotDataContext receiving DBContextOptions
/// </summary>
/// <param name="options">Options to use for configuration.</param>
public BotDataContext(DbContextOptions<BotDataContext> options)
: base(options)
{ }

/// <summary>
/// BotDataEntity records
/// </summary>
public virtual DbSet<BotDataEntity> BotDataEntity { get; set; }
_connectionString = connectionString;
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(_connectionString);
}
/// <summary>
/// Constructor for BotDataContext receiving DBContextOptions
/// </summary>
/// <param name="options">Options to use for configuration.</param>
public BotDataContext(DbContextOptions<BotDataContext> options)
: base(options)
{ }

base.OnConfiguring(optionsBuilder);
}
/// <summary>
/// BotDataEntity records
/// </summary>
public DbSet<BotDataEntity>? BotDataEntity { get; set; }

protected override void OnModelCreating(ModelBuilder builder)
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
builder.Entity<BotDataEntity>(entity =>
{
entity.ToTable(nameof(BotDataEntity));
entity.HasIndex(e => e.RealId);
entity.HasKey(e => e.Id);
});
optionsBuilder.UseSqlServer(_connectionString!);
}

base.OnConfiguring(optionsBuilder);
}

protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<BotDataEntity>(entity =>
{
entity.ToTable(nameof(BotDataEntity));
entity.HasIndex(e => e.RealId);
entity.HasKey(e => e.Id);
});
}


}
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
using System;
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bot.Builder.Community.Storage.EntityFramework
namespace Bot.Builder.Community.Storage.EntityFramework;

[Table("BotDataEntity")]
public class BotDataEntity
{
/// <summary>
/// BotDataEntity representing one bot data record.
/// Constructor for BotDataEntity
/// </summary>
[Table("BotDataEntity")]
public class BotDataEntity
/// <remarks>
/// Sets Timestamp to DateTimeOffset.UtfcNow
/// </remarks>
public BotDataEntity()
{
/// <summary>
/// Constructor for BotDataEntity
/// </summary>
/// <remarks>
/// Sets Timestamp to DateTimeOffset.UtfcNow
/// </remarks>
public BotDataEntity()
{
Timestamp = DateTimeOffset.UtcNow;
}

/// <summary>
/// Gets or sets the auto-generated Id/Key.
/// </summary>
/// <value>
/// The database generated Id/Key.
/// </value>
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
Timestamp = DateTimeOffset.UtcNow;
}

/// <summary>
/// Gets or sets the un-sanitized Id/Key.
/// </summary>
/// <value>
/// The un-sanitized Id/Key.
/// </value>
[MaxLength(1024)]
public string RealId { get; set; }
/// <summary>
/// Gets or sets the auto-generated Id/Key.
/// </summary>
/// <value>
/// The database generated Id/Key.
/// </value>
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }

/// <summary>
/// Gets or sets the persisted object's state.
/// </summary>
/// <value>
/// The persisted object's state.
/// </value>
[Column(TypeName = "nvarchar(MAX)")]
public string Document { get; set; }
/// <summary>
/// Gets or sets the un-sanitized Id/Key.
/// </summary>
/// <value>
/// The un-sanitized Id/Key.
/// </value>
[MaxLength(1024)]
public string? RealId { get; set; }

/// <summary>
/// Gets or sets the current timestamp.
/// </summary>
/// <value>
/// The current timestamp.
/// </value>
[Required]
[Timestamp]
public DateTimeOffset Timestamp { get; set; }
}
/// <summary>
/// Gets or sets the persisted object's state.
/// </summary>
/// <value>
/// The persisted object's state.
/// </value>
[Column(TypeName = "nvarchar(MAX)")]
public string? Document { get; set; }

/// <summary>
/// Gets or sets the current timestamp.
/// </summary>
/// <value>
/// The current timestamp.
/// </value>
[Required]
[Timestamp]
public DateTimeOffset? Timestamp { get; set; }
}
Loading