├── .gitignore
├── .vs
└── Poco.Sql.NetCore
│ └── v15
│ └── sqlite3
│ └── storage.ide
├── LICENSE
├── Logo.png
├── Poco.Sql.NetCore.Demo
├── Poco.Sql.NetCore.Demo.csproj
├── Program.cs
└── Properties
│ └── AssemblyInfo.cs
├── Poco.Sql.NetCore.Test.Models
├── Helper.cs
├── Mappings
│ ├── OrderMap.cs
│ ├── UserMap.cs
│ └── VUserMap.cs
├── Order.cs
├── Poco.Sql.NetCore.Test.Models.csproj
├── Properties
│ └── AssemblyInfo.cs
├── SuperUser.cs
├── User.cs
└── VUser.cs
├── Poco.Sql.NetCore.UnitTests
├── Poco.Sql.NetCore.UnitTests.csproj
├── PocoSqlTests.cs
└── UnitTestsRunner.cs
├── Poco.Sql.NetCore.sln
├── Poco.Sql.NetCore
├── Configuration.cs
├── Exceptions
│ ├── CantUpdateVirtualException.cs
│ └── NoSqlBuilderTaskFound.cs
├── Helpers
│ └── ExpressionEvaluator.cs
├── Interfaces
│ ├── IPocoSqlMapping.cs
│ └── IRelationshipMap.cs
├── Poco.Sql.NetCore.csproj
├── PocoSqlCostomMapping.cs
├── PocoSqlExtensions.cs
├── PocoSqlMapping.cs
├── PocoSqlStoredProcedureMap.cs
├── PocoSqlStoredProcedureMapping.cs
├── PocoSqlStoredProceduresMapping.cs
├── Properties
│ └── AssemblyInfo.cs
├── PropertyMap.cs
├── RelationshipMap.cs
├── SqlBuilder.cs
├── SqlBuilderTask.cs
├── StatementsCreator.cs
├── ValuesObject.cs
└── project.json
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.sln.docstates
8 |
9 | # Build results
10 | [Dd]ebug/
11 | [Dd]ebugPublic/
12 | [Rr]elease/
13 | [Rr]eleases/
14 | x64/
15 | x86/
16 | build/
17 | bld/
18 | [Bb]in/
19 | [Oo]bj/
20 |
21 | # Roslyn cache directories
22 | *.ide/
23 |
24 | # MSTest test Results
25 | [Tt]est[Rr]esult*/
26 | [Bb]uild[Ll]og.*
27 |
28 | #NUNIT
29 | *.VisualState.xml
30 | TestResult.xml
31 |
32 | # Build Results of an ATL Project
33 | [Dd]ebugPS/
34 | [Rr]eleasePS/
35 | dlldata.c
36 |
37 | *_i.c
38 | *_p.c
39 | *_i.h
40 | *.ilk
41 | *.meta
42 | *.obj
43 | *.pch
44 | *.pdb
45 | *.pgc
46 | *.pgd
47 | *.rsp
48 | *.sbr
49 | *.tlb
50 | *.tli
51 | *.tlh
52 | *.tmp
53 | *.tmp_proj
54 | *.log
55 | *.vspscc
56 | *.vssscc
57 | .builds
58 | *.pidb
59 | *.svclog
60 | *.scc
61 |
62 | # Chutzpah Test files
63 | _Chutzpah*
64 |
65 | # Visual C++ cache files
66 | ipch/
67 | *.aps
68 | *.ncb
69 | *.opensdf
70 | *.sdf
71 | *.cachefile
72 |
73 | # Visual Studio profiler
74 | *.psess
75 | *.vsp
76 | *.vspx
77 |
78 | # TFS 2012 Local Workspace
79 | $tf/
80 |
81 | # Guidance Automation Toolkit
82 | *.gpState
83 |
84 | # ReSharper is a .NET coding add-in
85 | _ReSharper*/
86 | *.[Rr]e[Ss]harper
87 | *.DotSettings.user
88 |
89 | # JustCode is a .NET coding addin-in
90 | .JustCode
91 |
92 | # TeamCity is a build add-in
93 | _TeamCity*
94 |
95 | # DotCover is a Code Coverage Tool
96 | *.dotCover
97 |
98 | # NCrunch
99 | _NCrunch_*
100 | .*crunch*.local.xml
101 |
102 | # MightyMoose
103 | *.mm.*
104 | AutoTest.Net/
105 |
106 | # Web workbench (sass)
107 | .sass-cache/
108 |
109 | # Installshield output folder
110 | [Ee]xpress/
111 |
112 | # DocProject is a documentation generator add-in
113 | DocProject/buildhelp/
114 | DocProject/Help/*.HxT
115 | DocProject/Help/*.HxC
116 | DocProject/Help/*.hhc
117 | DocProject/Help/*.hhk
118 | DocProject/Help/*.hhp
119 | DocProject/Help/Html2
120 | DocProject/Help/html
121 |
122 | # Click-Once directory
123 | publish/
124 |
125 | # Publish Web Output
126 | *.[Pp]ublish.xml
127 | *.azurePubxml
128 | # TODO: Comment the next line if you want to checkin your web deploy settings
129 | # but database connection strings (with potential passwords) will be unencrypted
130 | *.pubxml
131 | *.publishproj
132 |
133 | # NuGet Packages
134 | *.nupkg
135 | # The packages folder can be ignored because of Package Restore
136 | **/packages/*
137 | # except build/, which is used as an MSBuild target.
138 | !**/packages/build/
139 | # If using the old MSBuild-Integrated Package Restore, uncomment this:
140 | #!**/packages/repositories.config
141 |
142 | # Windows Azure Build Output
143 | csx/
144 | *.build.csdef
145 |
146 | # Windows Store app package directory
147 | AppPackages/
148 |
149 | # Others
150 | sql/
151 | *.Cache
152 | ClientBin/
153 | [Ss]tyle[Cc]op.*
154 | ~$*
155 | *~
156 | *.dbmdl
157 | *.dbproj.schemaview
158 | *.pfx
159 | *.publishsettings
160 | node_modules/
161 |
162 | # RIA/Silverlight projects
163 | Generated_Code/
164 |
165 | # Backup & report files from converting an old project file
166 | # to a newer Visual Studio version. Backup files are not needed,
167 | # because we have git ;-)
168 | _UpgradeReport_Files/
169 | Backup*/
170 | UpgradeLog*.XML
171 | UpgradeLog*.htm
172 |
173 | # SQL Server files
174 | *.mdf
175 | *.ldf
176 |
177 | # Business Intelligence projects
178 | *.rdl.data
179 | *.bim.layout
180 | *.bim_*.settings
181 |
182 | # Microsoft Fakes
183 | FakesAssemblies/
184 |
--------------------------------------------------------------------------------
/.vs/Poco.Sql.NetCore/v15/sqlite3/storage.ide:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developer82/Poco.Sql.NetCore/e48b2012ccb1fac6867ddf1c0dff3a0ea2f41a73/.vs/Poco.Sql.NetCore/v15/sqlite3/storage.ide
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Ophir Oren
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/Logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developer82/Poco.Sql.NetCore/e48b2012ccb1fac6867ddf1c0dff3a0ea2f41a73/Logo.png
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.Demo/Poco.Sql.NetCore.Demo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.0
5 | Poco.Sql.NetCore.Demo
6 | Exe
7 | Poco.Sql.NetCore.Demo
8 | $(PackageTargetFallback);dnxcore50
9 | false
10 | false
11 | false
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.Demo/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using Poco.Sql.NetCore.Exceptions;
5 | using Poco.Sql.NetCore.Test.Models;
6 | using Poco.Sql.NetCore.Test.Models.Mappings;
7 | using Poco.Sql.NetCore.UnitTests;
8 | using UnitTestRunner;
9 |
10 | namespace Poco.Sql.NetCore.Demo
11 | {
12 | public class Program
13 | {
14 | public static void Main(string[] args)
15 | {
16 | // TODO: Bug: Values are injected in WHERE statement when they should be parameterized
17 |
18 | Console.ForegroundColor = ConsoleColor.DarkGreen;
19 | Console.WriteLine(@" ____ __ ___ __ ____ __ __ ");
20 | Console.WriteLine(@"( _ \ / \ / __)/ \ / ___) / \ ( ) ");
21 | Console.WriteLine(@" ) __/( O )( (__( O )_ \___ \( O )/ (_/\");
22 | Console.WriteLine(@"(__) \__/ \___)\__/(_)(____/ \__\)\____/");
23 | Console.WriteLine("");
24 | Console.WriteLine("Poco.Sql");
25 | Console.WriteLine("Written by Ophir Oren. All rights reserved © Ophir Oren 2015-2018.");
26 | Console.WriteLine("Released under MIT license.");
27 | Console.WriteLine("http://www.webe.co.il");
28 | Console.WriteLine("");
29 | Console.ResetColor();
30 |
31 | TestRunner testRunner = new TestRunner();
32 | testRunner.RunTestClass(typeof(PocoSqlTests));
33 |
34 | // PocoSql configuration
35 | Configuration.Initialize(config =>
36 | {
37 | config.PluralizeTableNames();
38 | config.SetStoreProcedurePrefix("stp_");
39 | //config.ShowComments();
40 | //config.InjectValuesInQueies();
41 | //config.SelectFullGraph(); // TODO: not completed yet
42 |
43 | config.AddMap(new UserMap());
44 | config.AddMap(new OrderMap());
45 | config.AddMap(new VUserMap());
46 | });
47 |
48 | var user = Helper.GetUser();
49 | var vUser = Helper.GetVUser();
50 |
51 | Stopwatch swStopwatch = new Stopwatch();
52 | swStopwatch.Start();
53 | var currentlyTestingSql = user.PocoSql().Select().Where(u => u.Name.Equals("ophir")).ToString();
54 | swStopwatch.Stop();
55 |
56 | // Currently testing
57 | Console.WriteLine(
58 | Environment.NewLine +
59 | Environment.NewLine + "~~~~~~~~~~~~~~~~~~~~~~~~~" + Environment.NewLine + "Currently developing: " + Environment.NewLine + currentlyTestingSql);
60 | Console.WriteLine("Time elapsed: {0}", swStopwatch.Elapsed);
61 |
62 | Console.ReadLine();
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.Demo/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
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("Poco.Sql.NetCore.Demo")]
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("92de23aa-482e-437e-ab33-0b475321e95f")]
20 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.Test.Models/Helper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Poco.Sql.NetCore.Test.Models
6 | {
7 | public class Helper
8 | {
9 | public static User GetUser()
10 | {
11 | return new User()
12 | {
13 | UserId = 1,
14 | Age = 32,
15 | Name = "Ophir",
16 | Birthday = new DateTime(1982, 5, 6)
17 | };
18 | }
19 |
20 | public static VUser GetVUser()
21 | {
22 | return new VUser()
23 | {
24 | UserId = 1,
25 | Age = 32,
26 | Name = "Ophir",
27 | Birthday = new DateTime(1982, 5, 6)
28 | };
29 | }
30 |
31 | public static List GetListOfOrders()
32 | {
33 | var user = GetUser();
34 |
35 | return new List()
36 | {
37 | new Order() { UserId = 1, User = user, ItemName = "Item 1", OrderId = 1, Quantity = 5 },
38 | new Order() { UserId = 1, User = user, ItemName = "Item 2", OrderId = 1, Quantity = 4 },
39 | new Order() { UserId = 1, User = user, ItemName = "Item 3", OrderId = 1, Quantity = 3 },
40 | new Order() { UserId = 1, User = user, ItemName = "Item 4", OrderId = 1, Quantity = 2 },
41 | new Order() { UserId = 1, User = user, ItemName = "Item 5", OrderId = 1, Quantity = 1 }
42 | };
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.Test.Models/Mappings/OrderMap.cs:
--------------------------------------------------------------------------------
1 | namespace Poco.Sql.NetCore.Test.Models.Mappings
2 | {
3 | public class OrderMap : PocoSqlMapping
4 | {
5 | public OrderMap()
6 | {
7 | // Primary Key
8 | this.HasKey(t => t.OrderId);
9 |
10 | // Table & Column Mappings
11 | this.ToTable("Orders");
12 |
13 | this.HasOptional(t => t.User)
14 | .WithMany(t => t.Orders)
15 | .HasForeignKey(d => d.UserId);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.Test.Models/Mappings/UserMap.cs:
--------------------------------------------------------------------------------
1 | namespace Poco.Sql.NetCore.Test.Models.Mappings
2 | {
3 | public class UserMap : PocoSqlMapping
4 | {
5 | public UserMap()
6 | {
7 | // Primary Key
8 | this.HasKey(t => t.UserId).AutoGenerated();
9 |
10 | // Properties
11 | this.Property(t => t.Name)
12 | .IsRequired()
13 | .HasMaxLength(20);
14 |
15 | // Table & Column Mappings
16 | this.ToTable("Users");
17 | this.Property(t => t.Name).HasColumnName("Name");
18 | this.Property(t => t.Birthday).HasColumnName("DateOfBirth");
19 | this.Property(t => t.Age).Ignore();
20 |
21 | /*
22 | this.MapToStoredProcedures(s =>
23 | {
24 | s.Update().IncludeExecution().IncludeParameters(); //TODO: BUG - why does the result includes where caluse??? ---> exec stp_User_UpdateAge = @Age, Name = @Name, Birthday = @Birthday where UserId= 1;
25 | });
26 | */
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.Test.Models/Mappings/VUserMap.cs:
--------------------------------------------------------------------------------
1 | namespace Poco.Sql.NetCore.Test.Models.Mappings
2 | {
3 | public class VUserMap : PocoSqlMapping
4 | {
5 | public VUserMap()
6 | {
7 | // Primary Key
8 | this.HasKey(t => t.UserId);
9 |
10 | this.IsVirtual();
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.Test.Models/Order.cs:
--------------------------------------------------------------------------------
1 | namespace Poco.Sql.NetCore.Test.Models
2 | {
3 | public class Order
4 | {
5 | public int OrderId { get; set; }
6 | public int UserId { get; set; }
7 | public string ItemName { get; set; }
8 | public int Quantity { get; set; }
9 | public User User { get; set; }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.Test.Models/Poco.Sql.NetCore.Test.Models.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | Poco.Sql.NetCore.Test.Models
6 | Poco.Sql.NetCore.Test.Models
7 | $(PackageTargetFallback);dnxcore50
8 | false
9 | false
10 | false
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.Test.Models/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
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("Poco.Sql.NetCore.Test.Models")]
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("8f7297f4-4944-4262-9cdc-5831374172d7")]
20 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.Test.Models/SuperUser.cs:
--------------------------------------------------------------------------------
1 | namespace Poco.Sql.NetCore.Test.Models
2 | {
3 | public class SuperUser : User
4 | {
5 | public string Username { get; set; }
6 | public string Password { get; set; }
7 | public int Permissions { get; set; }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.Test.Models/User.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Poco.Sql.NetCore.Test.Models
5 | {
6 | public class User
7 | {
8 | public User()
9 | {
10 | Orders = new List();
11 | }
12 |
13 | public int UserId { get; set; }
14 | public int Age { get; set; }
15 | public string Name { get; set; }
16 | public DateTime Birthday { get; set; }
17 | public IList Orders { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.Test.Models/VUser.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Poco.Sql.NetCore.Test.Models
5 | {
6 | public class VUser
7 | {
8 | public VUser()
9 | {
10 | Orders = new List();
11 | }
12 |
13 | public int UserId { get; set; }
14 | public int Age { get; set; }
15 | public string Name { get; set; }
16 | public DateTime Birthday { get; set; }
17 | public IList Orders { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.UnitTests/Poco.Sql.NetCore.UnitTests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.0
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.UnitTests/PocoSqlTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection.Metadata;
3 | using FluentAssertions;
4 | using Microsoft.VisualStudio.TestTools.UnitTesting;
5 | using Poco.Sql.NetCore.Test.Models;
6 | using Poco.Sql.NetCore.Test.Models.Mappings;
7 |
8 | namespace Poco.Sql.NetCore.UnitTests
9 | {
10 | [TestClass]
11 | public class PocoSqlTests
12 | {
13 | private User _user;
14 | private VUser _vUser;
15 |
16 | public PocoSqlTests()
17 | {
18 | Configuration.Initialize(config =>
19 | {
20 | config.PluralizeTableNames();
21 | config.SetStoreProcedurePrefix("stp_");
22 | //config.ShowComments();
23 | //config.InjectValuesInQueies();
24 | //config.SelectFullGraph(); // TODO: not completed yet
25 |
26 | config.AddMap(new UserMap());
27 | config.AddMap(new OrderMap());
28 | config.AddMap(new VUserMap());
29 | });
30 |
31 | _user = Helper.GetUser();
32 | _vUser = Helper.GetVUser();
33 | }
34 |
35 | [TestMethod]
36 | public void Generate_Select_Query_From_Object()
37 | {
38 | string sql = _user.PocoSql().Select().ToString();
39 | sql.Should().Be("select UserId, Age, Name, DateOfBirth as Birthday from Users;");
40 | }
41 |
42 | [TestMethod]
43 | public void Generate_Insert_Statement_From_Object()
44 | {
45 | var sql = _user.PocoSql().Insert().ToString();
46 | sql.Should().Be("insert into Users (Age, Name, Birthday) values(@Age, @Name, @Birthday);");
47 | }
48 |
49 | [TestMethod]
50 | public void Generate_Update_Statement_From_Object()
51 | {
52 | var sql = _user.PocoSql().Update().ToString();
53 | sql.Should().Be("update Users set Age = @Age, Name = @Name, Birthday = @Birthday where (UserId = @UserId);");
54 | }
55 |
56 | [TestMethod]
57 | public void Generate_Delete_Statement_From_Object()
58 | {
59 | var sql = _user.PocoSql().Delete().ToString();
60 | sql.Should().Be("delete from Users where (UserId = @UserId);");
61 | }
62 |
63 | [TestMethod]
64 | public void Generate_Select_Query_From_Object_With_Virtual_Mapping()
65 | {
66 | var sql = _vUser.PocoSql().Select().ToString();
67 | sql.Should().Be("select UserId, Age, Name, Birthday from VUser;");
68 | }
69 |
70 | [TestMethod]
71 | public void Generate_Select_Query_With_Where_From_Object_With_Virtual_Mapping()
72 | {
73 | var sql = _vUser.PocoSql().Select().Where(u => u.UserId == 1).ToString();
74 | sql.Should().Be("select UserId, Age, Name, Birthday from VUser where ((UserId = @UserId));");
75 | }
76 |
77 | [TestMethod]
78 | public void Generate_Select_Query_With_DateTime_Where_From_Object_With_Virtual_Mapping()
79 | {
80 | DateTime fiftyYears = DateTime.Now.AddYears(-50);
81 | DateTime now = DateTime.Now;
82 | var sql = _vUser.PocoSql().Select().Where(u => u.Birthday > fiftyYears && u.Birthday < now).ToString(); // TODO: this query is not performing correctly
83 | sql.Should().Be($"select UserId, Age, Name, Birthday from VUser where(((Birthday > {fiftyYears}) and(Birthday < {now})));");
84 | }
85 |
86 | [TestMethod]
87 | [ExpectedException(typeof(Exceptions.CantUpdateVirtualException))]
88 | public void Insert_Or_Update_Statements_On_Virtual_Mapping_Objects_Should_Throw_Exception()
89 | {
90 | var sql = _vUser.PocoSql().Insert().ToString();
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.UnitTests/UnitTestsRunner.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Poco.Sql.NetCore.UnitTests
6 | {
7 | public class UnitTestsRunner
8 | {
9 | public bool RunTest(Action testMethod)
10 | {
11 | try
12 | {
13 | testMethod.Invoke();
14 | return true;
15 | }
16 | catch (Exception e)
17 | {
18 | return false;
19 | }
20 | }
21 |
22 | public bool RunTest(Action testMethod, string testText, string passText, string failText)
23 | {
24 | if (RunTest(testMethod))
25 | {
26 |
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26730.12
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Poco.Sql.NetCore.Demo", "Poco.Sql.NetCore.Demo\Poco.Sql.NetCore.Demo.csproj", "{92DE23AA-482E-437E-AB33-0B475321E95F}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Poco.Sql.NetCore.Test.Models", "Poco.Sql.NetCore.Test.Models\Poco.Sql.NetCore.Test.Models.csproj", "{8F7297F4-4944-4262-9CDC-5831374172D7}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Poco.Sql.NetCore", "Poco.Sql.NetCore\Poco.Sql.NetCore.csproj", "{A51E327A-41F0-46A6-8892-AEF5E40ECCD0}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Poco.Sql.NetCore.UnitTests", "Poco.Sql.NetCore.UnitTests\Poco.Sql.NetCore.UnitTests.csproj", "{6E86D7F1-4B91-4C4F-A1E9-09E49DF7C477}"
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 | {92DE23AA-482E-437E-AB33-0B475321E95F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {92DE23AA-482E-437E-AB33-0B475321E95F}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {92DE23AA-482E-437E-AB33-0B475321E95F}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {92DE23AA-482E-437E-AB33-0B475321E95F}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {8F7297F4-4944-4262-9CDC-5831374172D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {8F7297F4-4944-4262-9CDC-5831374172D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {8F7297F4-4944-4262-9CDC-5831374172D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {8F7297F4-4944-4262-9CDC-5831374172D7}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {A51E327A-41F0-46A6-8892-AEF5E40ECCD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {A51E327A-41F0-46A6-8892-AEF5E40ECCD0}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {A51E327A-41F0-46A6-8892-AEF5E40ECCD0}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {A51E327A-41F0-46A6-8892-AEF5E40ECCD0}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {6E86D7F1-4B91-4C4F-A1E9-09E49DF7C477}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {6E86D7F1-4B91-4C4F-A1E9-09E49DF7C477}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {6E86D7F1-4B91-4C4F-A1E9-09E49DF7C477}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {6E86D7F1-4B91-4C4F-A1E9-09E49DF7C477}.Release|Any CPU.Build.0 = Release|Any CPU
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | GlobalSection(ExtensibilityGlobals) = postSolution
41 | SolutionGuid = {EF3D776C-A417-4271-9CA0-14BB4D64C598}
42 | EndGlobalSection
43 | EndGlobal
44 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore/Configuration.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Poco.Sql.NetCore.Interfaces;
4 |
5 | namespace Poco.Sql.NetCore
6 | {
7 | public class Configuration
8 | {
9 | private static Object _lock = new Object();
10 | private static bool _initialized;
11 | private static Dictionary _mappings = new Dictionary();
12 |
13 | internal static bool IsPluralizeTableNames { get; private set; }
14 | internal static bool FullGraphSelecttion { get; private set; }
15 | internal static bool ValuesInQueies { get; private set; }
16 | internal static bool CachingDisabled { get; private set; }
17 | internal static bool Comment { get; private set; }
18 | internal static string StoredProceduresPrefix { get; private set; }
19 | internal static Dictionary Mappings = new Dictionary();
20 |
21 | public static void Initialize(Action config)
22 | {
23 | if (_initialized) return;
24 |
25 | lock (_lock)
26 | {
27 | if (_initialized) return;
28 | config.Invoke(new Configuration());
29 | _initialized = true;
30 | }
31 | }
32 |
33 | public void PluralizeTableNames()
34 | {
35 | IsPluralizeTableNames = true;
36 | }
37 |
38 | public void SelectFullGraph()
39 | {
40 | FullGraphSelecttion = true;
41 | }
42 |
43 | public void InjectValuesInQueies()
44 | {
45 | ValuesInQueies = true;
46 | }
47 |
48 | public void DisableCache()
49 | {
50 | CachingDisabled = true;
51 | }
52 |
53 | public void ShowComments()
54 | {
55 | Comment = true;
56 | }
57 |
58 | public void SetStoreProcedurePrefix(string prefix)
59 | {
60 | StoredProceduresPrefix = prefix;
61 | }
62 |
63 | public void AddMap(PocoSqlMapping mapping)
64 | {
65 | _mappings.Add(typeof(T).FullName, mapping);
66 | }
67 |
68 | internal static bool HasMap(string key)
69 | {
70 | return _mappings.ContainsKey(key);
71 | }
72 |
73 | internal static IPocoSqlMapping GetMap(string key)
74 | {
75 | return (IPocoSqlMapping)_mappings[key];
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore/Exceptions/CantUpdateVirtualException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Poco.Sql.NetCore.Exceptions
4 | {
5 | public class CantUpdateVirtualException : Exception
6 | {
7 | public override string Message
8 | {
9 | get
10 | {
11 | return "You are trying to create a SQL statement for virtual/view mapping object, which does not represet an actual table in the database";
12 | }
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore/Exceptions/NoSqlBuilderTaskFound.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Poco.Sql.NetCore.Exceptions
4 | {
5 | public class NoSqlBuilderTaskFound : Exception
6 | {
7 | public override string Message
8 | {
9 | get
10 | {
11 | return "No tasks were found for sql build.";
12 | }
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Poco.Sql.NetCore/Helpers/ExpressionEvaluator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq.Expressions;
3 |
4 | namespace Poco.Sql.NetCore.Helpers
5 | {
6 | class ExpressionEvaluator
7 | {
8 | #region Eval
9 | internal static string Eval(object expression, bool injectValuesToQueies)
10 | {
11 | return Eval(expression, null, String.Empty, injectValuesToQueies);
12 | }
13 |
14 | internal static string Eval(object expression, object parentExpression, string statementStr, bool injectValuesToQueies)
15 | {
16 | if (expression is BinaryExpression)
17 | statementStr += processBinaryExpression((BinaryExpression)expression, injectValuesToQueies);
18 | else if (expression is MethodCallExpression)
19 | statementStr += processMethodCallExpression((MethodCallExpression)expression, (Expression)parentExpression, injectValuesToQueies);
20 | else if (expression is UnaryExpression)
21 | statementStr += processUnaryExpression((UnaryExpression)expression, (Expression)expression, injectValuesToQueies);
22 | else if (expression is MemberExpression)
23 | statementStr += processMemberExpression((MemberExpression)expression, parentExpression, injectValuesToQueies);
24 | else if (expression is ConstantExpression)
25 | statementStr += processConstantExpression((ConstantExpression)expression, parentExpression, injectValuesToQueies);
26 |
27 | return statementStr;
28 | }
29 | #endregion
30 |
31 | #region processBinaryExpression
32 | private static string processBinaryExpression(BinaryExpression binaryExpression, bool injectValuesToQueies)
33 | {
34 | string result;
35 |
36 | var leftExpression = binaryExpression.Left;
37 | var rightExpression = binaryExpression.Right;
38 |
39 | result = String.Format("({0}{1}{2})",
40 | Eval(leftExpression, binaryExpression, String.Empty, injectValuesToQueies),
41 | convertNodeTypeToStr(binaryExpression.NodeType),
42 | Eval(rightExpression, binaryExpression, String.Empty, injectValuesToQueies));
43 |
44 | return result;
45 | }
46 | #endregion
47 |
48 | #region processMethodCallExpression
49 | private static string processMethodCallExpression(MethodCallExpression methodCallExpression, Expression parentExpression, bool injectValuesToQueies)
50 | {
51 | string result = String.Empty;
52 | string constantExpressionValue = String.Empty;
53 |
54 | if (methodCallExpression.Arguments.Count > 0)
55 | {
56 | if (methodCallExpression.Arguments[0] is ConstantExpression)
57 | constantExpressionValue = ((ConstantExpression) methodCallExpression.Arguments[0]).Value.ToString();
58 | else if (methodCallExpression.Arguments[0] is MemberExpression)
59 | constantExpressionValue = processMemberExpression((MemberExpression) methodCallExpression.Arguments[0],
60 | parentExpression, injectValuesToQueies);
61 | }
62 |
63 | var expressionStr = methodCallExpression.Object.ToString();
64 | expressionStr = expressionStr.Substring(expressionStr.LastIndexOf('.') + 1);
65 |
66 | var value = String.Empty;
67 | var valueWrapper = methodCallExpression.Object.Type == typeof(String) ? "'" : String.Empty;
68 | var entireExpStr = methodCallExpression.ToString();
69 |
70 | if (entireExpStr.IndexOf(".Equals") > -1)
71 | {
72 | if (!injectValuesToQueies)
73 | {
74 | constantExpressionValue = "@" + expressionStr;
75 | valueWrapper = String.Empty;
76 | }
77 |
78 | result = String.Format("{0} = {1}{2}{1}",
79 | expressionStr,
80 | valueWrapper,
81 | constantExpressionValue);
82 | }
83 | else if (entireExpStr.IndexOf(".IndexOf") > -1)
84 | {
85 | BinaryExpression binaryParentExp = (BinaryExpression)parentExpression;
86 | int indexOfComparisonValue = Expression.Lambda>(binaryParentExp.Right).Compile().Invoke();
87 |
88 | if (methodCallExpression.NodeType == ExpressionType.GreaterThan && indexOfComparisonValue == -1)
89 | {
90 | result = String.Format(" like '%{0}%'", constantExpressionValue);
91 | }
92 | }
93 | else
94 | {
95 | string expressionValue = getExpressionValue(methodCallExpression);
96 | if (String.IsNullOrEmpty(expressionValue))
97 | result = expressionStr;
98 | else
99 | result = expressionValue;
100 | }
101 |
102 | return result;
103 | }
104 | #endregion
105 |
106 | #region processUnaryExpression
107 | private static string processUnaryExpression(UnaryExpression unaryExpression, Expression parentExpression, bool injectValuesToQueies)
108 | {
109 | string result = String.Empty;
110 |
111 | if (unaryExpression.NodeType == ExpressionType.Not || unaryExpression.NodeType == ExpressionType.NotEqual)
112 | result = "not ";
113 |
114 | result += Eval(unaryExpression.Operand, parentExpression, String.Empty, injectValuesToQueies);
115 | return result;
116 | }
117 | #endregion
118 |
119 | #region processMemberExpression
120 | private static string processMemberExpression(MemberExpression memberExpression, object parentExpression, bool injectValuesToQueies)
121 | {
122 | string result = String.Empty;
123 | if (memberExpression.Expression is ConstantExpression)
124 | {
125 | if (!injectValuesToQueies && parentExpression is BinaryExpression)
126 | return getParameterziedValue(memberExpression, (BinaryExpression)parentExpression);
127 |
128 | return getExpressionValue(memberExpression);
129 | }
130 | else
131 | {
132 | result = memberExpression.ToString();
133 | result = result.Substring(result.LastIndexOf('.') + 1);
134 | }
135 | return result;
136 | }
137 | #endregion
138 |
139 | #region processConstantExpression
140 | private static string processConstantExpression(ConstantExpression expression, object parentExpression, bool injectValuesToQueies)
141 | {
142 | if (!injectValuesToQueies && parentExpression is BinaryExpression)
143 | return getParameterziedValue(expression, (BinaryExpression)parentExpression);
144 |
145 | return expression.ToString();
146 | }
147 | #endregion
148 |
149 | #region getExpressionValue
150 | private static string getExpressionValue(Expression expression)
151 | {
152 | try
153 | {
154 | Expression conversion = Expression.Convert(expression, typeof(object));
155 | Func