Initial commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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="entityFramework" connectionString="Server=tcp:nlcc.database.windows.net,1433;Initial Catalog=NLCC;Persist Security Info=False;User ID=yuanson;Password=8ik,9ol.;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" providerName="System.Data.SqlClient"/>
|
||||
<!--<add name="entityFramework" connectionString="Data Source=(local)\;Initial Catalog=LifeSpring;User ID=sa;Password=9999;" providerName="System.Data.SqlClient"/>-->
|
||||
</connectionStrings>
|
||||
<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>
|
||||
</configuration>
|
||||
@@ -0,0 +1,82 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{4334D169-3877-4E4C-B8A9-9382FD0A1BD6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Church.Net.DAL.EF</RootNamespace>
|
||||
<AssemblyName>Church.Net.DAL.EF</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.AspNet.Identity.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Identity.Core.2.2.2\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.AspNet.Identity.EntityFramework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Identity.EntityFramework.2.2.2\lib\net45\Microsoft.AspNet.Identity.EntityFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ChurchNetContext.cs" />
|
||||
<Compile Include="Migrations\Configuration.cs" />
|
||||
<Compile Include="NewVisitorDAL.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RepositoryBase.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Chruch.Net.DAL.Core\Church.Net.DAL.Core.csproj">
|
||||
<Project>{b9d6f9dc-8eb4-44e2-8625-98dfa2958084}</Project>
|
||||
<Name>Church.Net.DAL.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Church.Net.Utility\Church.Net.Utility.csproj">
|
||||
<Project>{606e98ab-096a-46ed-8e2e-4eb5ce4ec553}</Project>
|
||||
<Name>Church.Net.Utility</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Data.Entity.ModelConfiguration.Conventions;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Church.Net.Entity;
|
||||
using Microsoft.AspNet.Identity.EntityFramework;
|
||||
|
||||
namespace Church.Net.DAL.EF
|
||||
{
|
||||
//public class ChurchNetContext:DbContext
|
||||
//{
|
||||
// public ChurchNetContext():base("entityFramework")
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
// public ChurchNetContext(string connString):base(connString)
|
||||
// {
|
||||
|
||||
// }
|
||||
// //public DbSet<PastoralDomain> PastoralDomains { get; set; }
|
||||
// //public DbSet<FamilyMember> FamilyMembers { get; set; }
|
||||
// //public DbSet<Career> Careers { get; set; }
|
||||
// public DbSet<NewVisitor> NewVisitors { get; set; }
|
||||
// //public DbSet<Religion> Religions { get; set; }
|
||||
|
||||
|
||||
// protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
||||
// {
|
||||
// modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
public class ChurchNetContext : IdentityDbContext<FamilyMember>
|
||||
{
|
||||
public ChurchNetContext()
|
||||
: base("entityFramework")
|
||||
{
|
||||
}
|
||||
public ChurchNetContext(string connString) : base(connString)
|
||||
{
|
||||
|
||||
}
|
||||
//public DbSet<PastoralDomain> PastoralDomains { get; set; }
|
||||
//public DbSet<FamilyMember> FamilyMembers { get; set; }
|
||||
//public DbSet<Career> Careers { get; set; }
|
||||
public static ChurchNetContext Create()
|
||||
{
|
||||
return new ChurchNetContext();
|
||||
}
|
||||
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<IdentityUserLogin>().HasKey<string>(l => l.UserId);
|
||||
modelBuilder.Entity<IdentityRole>().HasKey<string>(r => r.Id);
|
||||
modelBuilder.Entity<IdentityUserRole>().HasKey(r => new { r.RoleId, r.UserId });
|
||||
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
|
||||
|
||||
|
||||
modelBuilder.Entity<PastoralDomainMembers>()
|
||||
.HasKey(cp => new { cp.FamilyMemberId, cp.PastoralDomainId });
|
||||
|
||||
modelBuilder.Entity<FamilyMember>()
|
||||
.HasMany(c => c.PastoralDomains)
|
||||
.WithRequired()
|
||||
.HasForeignKey(cp => cp.FamilyMemberId);
|
||||
|
||||
modelBuilder.Entity<PastoralDomain>()
|
||||
.HasMany(p => p.Members)
|
||||
.WithRequired()
|
||||
.HasForeignKey(cp => cp.PastoralDomainId);
|
||||
}
|
||||
|
||||
//public System.Data.Entity.DbSet<Church.Net.Entity.FamilyMember> FamilyMembers { get; set; }
|
||||
|
||||
public DbSet<NewVisitor> NewVisitors { get; set; }
|
||||
public DbSet<Religion> Religions { get; set; }
|
||||
|
||||
public DbSet<PastoralDomainMembers> PastoralDomainMembers { get; set; }
|
||||
|
||||
public System.Data.Entity.DbSet<Church.Net.Entity.Career> Careers { get; set; }
|
||||
|
||||
public System.Data.Entity.DbSet<Church.Net.Entity.PastoralDomain> PastoralDomains { get; set; }
|
||||
public DbSet<WhoIsSpy> WhoIsSpy { get; set; }
|
||||
public DbSet<Vocabulary> Vocabulary { get; set; }
|
||||
public DbSet<HappinessGroup> HappinessGroups { get; set; }
|
||||
public DbSet<HappinessBEST> HappinessBESTs { get; set; }
|
||||
public DbSet<HappinessWeek> HappinessWeeks { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace Church.Net.DAL.EF.Migrations
|
||||
{
|
||||
using System;
|
||||
using System.Data.Entity;
|
||||
using System.Data.Entity.Migrations;
|
||||
using System.Linq;
|
||||
|
||||
internal sealed class Configuration : DbMigrationsConfiguration<Church.Net.DAL.EF.ChurchNetContext>
|
||||
{
|
||||
public Configuration()
|
||||
{
|
||||
AutomaticMigrationsEnabled = true;
|
||||
AutomaticMigrationDataLossAllowed = true;
|
||||
ContextKey = "Church.Net.DAL.EF.ChurchNetContext";
|
||||
}
|
||||
|
||||
protected override void Seed(Church.Net.DAL.EF.ChurchNetContext context)
|
||||
{
|
||||
// This method will be called after migrating to the latest version.
|
||||
|
||||
// You can use the DbSet<T>.AddOrUpdate() helper extension method
|
||||
// to avoid creating duplicate seed data.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Church.Net.Entity;
|
||||
|
||||
namespace Church.Net.DAL.EF
|
||||
{
|
||||
public class NewVisitorDAL:RepositoryBase<NewVisitor>
|
||||
{
|
||||
public NewVisitorDAL(string connString) : base(connString)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 組件的一般資訊是由下列的屬性集控制。
|
||||
// 變更這些屬性的值即可修改組件的相關
|
||||
// 資訊。
|
||||
[assembly: AssemblyTitle("Church.Net.DAL.FamilyMembers")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Church.Net.DAL.FamilyMembers")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 將 ComVisible 設為 false 可對 COM 元件隱藏
|
||||
// 組件中的類型。若必須從 COM 存取此組件中的類型,
|
||||
// 的類型,請在該類型上將 ComVisible 屬性設定為 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 下列 GUID 為專案公開 (Expose) 至 COM 時所要使用的 typelib ID
|
||||
[assembly: Guid("4334d169-3877-4e4c-b8a9-9382fd0a1bd6")]
|
||||
|
||||
// 組件的版本資訊由下列四個值所組成:
|
||||
//
|
||||
// 主要版本
|
||||
// 次要版本
|
||||
// 組建編號
|
||||
// 修訂編號
|
||||
//
|
||||
// 您可以指定所有的值,或將組建編號或修訂編號設為預設值
|
||||
//方法是使用 '*',如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.10")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.10")]
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Church.Net.DAL.Core;
|
||||
|
||||
namespace Church.Net.DAL.EF
|
||||
{
|
||||
public class RepositoryBase<T> : IRepository<T> where T : class
|
||||
|
||||
{
|
||||
private ChurchNetContext db = null;
|
||||
private DbSet<T> dbSet = null;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
db?.Dispose();
|
||||
|
||||
}
|
||||
|
||||
public RepositoryBase(string connString)
|
||||
{
|
||||
InitializeConnectionString(connString);
|
||||
}
|
||||
|
||||
public void InitializeConnectionString(string connString)
|
||||
{
|
||||
db = new ChurchNetContext(connString);
|
||||
|
||||
foreach (PropertyInfo propertyInfo in db.GetType().GetProperties())
|
||||
{
|
||||
if (propertyInfo.PropertyType == typeof(DbSet<T>))
|
||||
{
|
||||
dbSet = (DbSet<T>) propertyInfo.GetValue(db, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(T obj)
|
||||
{
|
||||
dbSet.Add(obj);
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
public void Edit(T obj)
|
||||
{
|
||||
dbSet.Attach(obj);
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
public void Delete(T obj)
|
||||
{
|
||||
dbSet.Remove(obj);
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
public void Attach(T obj)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public T GetSingle()
|
||||
{
|
||||
return dbSet.First();
|
||||
}
|
||||
|
||||
public T GetSingle(Expression<Func<T, bool>> whereCondition)
|
||||
{
|
||||
return dbSet.Where(whereCondition).FirstOrDefault();
|
||||
}
|
||||
|
||||
public IList<T> GetAll()
|
||||
{
|
||||
return dbSet.ToList();
|
||||
}
|
||||
|
||||
public IList<T> GetAll(Expression<Func<T, bool>> whereCondition)
|
||||
{
|
||||
return dbSet.Where(whereCondition).ToList();
|
||||
}
|
||||
|
||||
public IQueryable<T> GetQueryable()
|
||||
{
|
||||
return dbSet;
|
||||
}
|
||||
|
||||
public IQueryable<T> GetQueryable(Expression<Func<T, bool>> whereCondition)
|
||||
{
|
||||
return dbSet.Where(whereCondition);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="EntityFramework" version="6.2.0" targetFramework="net461" />
|
||||
<package id="EntityFramework.zh-Hant" version="6.2.0" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.Identity.Core" version="2.2.2" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.Identity.EntityFramework" version="2.2.2" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user