Skip to content

Commit ae1a0ba

Browse files
committed
initial
1 parent 503e90a commit ae1a0ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1914
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.vs
2+
/src/FileContextCore/bin
3+
/src/FileContextCore/obj
4+
/src/Example/bin
5+
/src/Example/obj

FileContextCore.sln

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26228.4
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2ED3EC6D-B2EF-4643-9002-0E9FD879E92D}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5B1AD4C3-7E21-4327-97B5-FC886D6750C5}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileContextCore", "src\FileContextCore\FileContextCore.csproj", "{571D089B-52FF-466F-B666-5AA64644D333}"
11+
EndProject
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example", "src\Example\Example.csproj", "{51494293-60AC-4DE1-889C-B7F41CBF6D96}"
13+
EndProject
14+
Global
15+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16+
Debug|Any CPU = Debug|Any CPU
17+
Release|Any CPU = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
20+
{571D089B-52FF-466F-B666-5AA64644D333}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{571D089B-52FF-466F-B666-5AA64644D333}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{571D089B-52FF-466F-B666-5AA64644D333}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{571D089B-52FF-466F-B666-5AA64644D333}.Release|Any CPU.Build.0 = Release|Any CPU
24+
{51494293-60AC-4DE1-889C-B7F41CBF6D96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{51494293-60AC-4DE1-889C-B7F41CBF6D96}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{51494293-60AC-4DE1-889C-B7F41CBF6D96}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{51494293-60AC-4DE1-889C-B7F41CBF6D96}.Release|Any CPU.Build.0 = Release|Any CPU
28+
EndGlobalSection
29+
GlobalSection(SolutionProperties) = preSolution
30+
HideSolutionNode = FALSE
31+
EndGlobalSection
32+
GlobalSection(NestedProjects) = preSolution
33+
{571D089B-52FF-466F-B666-5AA64644D333} = {2ED3EC6D-B2EF-4643-9002-0E9FD879E92D}
34+
{51494293-60AC-4DE1-889C-B7F41CBF6D96} = {2ED3EC6D-B2EF-4643-9002-0E9FD879E92D}
35+
EndGlobalSection
36+
EndGlobal

src/Example/Data/Context.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.EntityFrameworkCore;
6+
using Example.Data.Entities;
7+
using FileContextCore.Extensions;
8+
9+
namespace Example.Data
10+
{
11+
public class Context : DbContext
12+
{
13+
public DbSet<User> Users { get; set; }
14+
15+
public DbSet<Content> Contents { get; set; }
16+
17+
public DbSet<Setting> Settings { get; set; }
18+
19+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
20+
{
21+
optionsBuilder.UseFileContext(new FileContextCore.Serializer.XMLSerializer());
22+
}
23+
24+
protected override void OnModelCreating(ModelBuilder modelBuilder)
25+
{
26+
27+
}
28+
}
29+
}

src/Example/Data/Entities/Base.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
7+
namespace Example.Data.Entities
8+
{
9+
public class Base
10+
{
11+
public Base()
12+
{
13+
//Id = Guid.NewGuid();
14+
CreatedOn = DateTime.UtcNow;
15+
}
16+
17+
[Key]
18+
public int Id { get; set; }
19+
20+
public DateTime CreatedOn { get; set; }
21+
22+
public DateTime UpdatedOn { get; set; }
23+
}
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations.Schema;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
7+
namespace Example.Data.Entities
8+
{
9+
public class Content : Base
10+
{
11+
public string Text { get; set; }
12+
13+
[ForeignKey("User")]
14+
public int UserId { get; set; }
15+
16+
public virtual User User { get; set; }
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations.Schema;
4+
using System.Text;
5+
6+
namespace Example.Data.Entities
7+
{
8+
public class Setting : Base
9+
{
10+
[ForeignKey("User")]
11+
public int UserId { get; set; }
12+
13+
public virtual User User { get; set; }
14+
15+
public string Key { get; set; }
16+
17+
public string Value { get; set; }
18+
}
19+
}

src/Example/Data/Entities/User.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace Example.Data.Entities
7+
{
8+
public class User : Base
9+
{
10+
public string Username { get; set; }
11+
12+
public string Name { get; set; }
13+
14+
public virtual List<Content> Contents { get; set; }
15+
16+
public virtual List<Setting> Settings { get; set; }
17+
}
18+
}

src/Example/Example.csproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp1.0</TargetFramework>
5+
<AssemblyName>Example</AssemblyName>
6+
<OutputType>Exe</OutputType>
7+
<PackageId>Example</PackageId>
8+
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>
9+
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
10+
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
11+
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
12+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\FileContextCore\FileContextCore.csproj" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
21+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.1" />
22+
</ItemGroup>
23+
24+
</Project>

src/Example/Program.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using Example.Data;
2+
using Example.Data.Entities;
3+
using Microsoft.EntityFrameworkCore;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
9+
namespace Example
10+
{
11+
public class Program
12+
{
13+
public static void Main(string[] args)
14+
{
15+
Context db = new Context();
16+
17+
//db.Database.EnsureCreated();
18+
19+
//db.Database.EnsureDeleted();
20+
21+
List<User> users = db.Users.Include(x => x.Contents)/*.Include(x => x.Settings)*/.ToList();
22+
23+
List<Content> contents = db.Contents.Include(x => x.User).ToList();
24+
25+
IEnumerable<User> test = db.Users;
26+
27+
User us = new User()
28+
{
29+
Name = "Morris Janatzek",
30+
Username = "astalawixer"
31+
};
32+
33+
db.Users.Add(us);
34+
35+
db.Contents.Add(new Content()
36+
{
37+
Text = "Test",
38+
UserId = us.Id
39+
});
40+
41+
db.SaveChanges();
42+
43+
Console.WriteLine(db.Contents.Count());
44+
Console.WriteLine(db.Users.Count());
45+
46+
Context db2 = new Context();
47+
Console.WriteLine(db2.Contents.Count());
48+
Console.WriteLine(db2.Users.Count());
49+
50+
db.Users.Add(new User()
51+
{
52+
Username = "test123",
53+
Name = "Test Test"
54+
});
55+
56+
db.Users.Add(new User()
57+
{
58+
Username = "test234",
59+
Name = "Test Test 2"
60+
});
61+
62+
db.Users.Add(new User()
63+
{
64+
Username = "test567",
65+
Name = "Test Test 3"
66+
});
67+
68+
db.SaveChanges();
69+
70+
Console.WriteLine(db.Users.Count());
71+
Console.WriteLine(db2.Users.Count());
72+
73+
Console.ReadKey();
74+
}
75+
}
76+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyConfiguration("")]
9+
[assembly: AssemblyCompany("")]
10+
[assembly: AssemblyProduct("Example")]
11+
[assembly: AssemblyTrademark("")]
12+
13+
// Setting ComVisible to false makes the types in this assembly not visible
14+
// to COM components. If you need to access a type in this assembly from
15+
// COM, set the ComVisible attribute to true on that type.
16+
[assembly: ComVisible(false)]
17+
18+
// The following GUID is for the ID of the typelib if this project is exposed to COM
19+
[assembly: Guid("51494293-60ac-4de1-889c-b7f41cbf6d96")]

0 commit comments

Comments
 (0)