├── icon.jpg ├── remark.txt ├── MegoPublicKey.snk ├── test └── Caredev.Mego.Tests │ ├── Resources │ ├── EmptyAccess2000.mdb │ ├── EmptyAccess2003.mdb │ ├── EmptyExcel2003.xls │ ├── EmptyExcel2010.xlsx │ └── EmptyAccess2010.accdb │ ├── MySql │ ├── FunctionTest.cs │ ├── Query │ │ ├── Simple │ │ │ ├── SqlQueryTest.cs │ │ │ └── SingleEntityTest.cs │ │ └── Inherit │ │ │ ├── SqlQueryTest.cs │ │ │ └── SingleEntityTest.cs │ ├── Constants.cs │ └── Commit │ │ └── Simple │ │ └── DeleteTest.cs │ ├── SqlServer │ ├── FunctionTest.cs │ ├── Query │ │ ├── Simple │ │ │ ├── SqlQueryTest.cs │ │ │ └── SingleEntityTest.cs │ │ └── Inherit │ │ │ ├── SqlQueryTest.cs │ │ │ └── SingleEntityTest.cs │ └── Constants.cs │ ├── Access │ ├── Query │ │ └── Simple │ │ │ ├── SqlQueryTest.cs │ │ │ └── SingleEntityTest.cs │ ├── Constants.cs │ └── Commit │ │ └── Simple │ │ ├── DeleteTest.cs │ │ └── UpdatePropertysTest.cs │ ├── Excel │ ├── Query │ │ └── Simple │ │ │ ├── SqlQueryTest.cs │ │ │ └── SingleEntityTest.cs │ ├── Constants.cs │ └── Commit │ │ └── Simple │ │ └── UpdatePropertysTest.cs │ ├── SqlServerCe │ ├── Query │ │ └── Simple │ │ │ ├── SqlQueryTest.cs │ │ │ └── SingleEntityTest.cs │ ├── Constants.cs │ ├── Commit │ │ └── Simple │ │ │ ├── DeleteTest.cs │ │ │ └── UpdatePropertysTest.cs │ └── DbFeatureTest.cs │ ├── SQLite │ ├── Query │ │ ├── Simple │ │ │ ├── SqlQueryTest.cs │ │ │ └── SingleEntityTest.cs │ │ └── Inherit │ │ │ ├── SqlQueryTest.cs │ │ │ └── SingleEntityTest.cs │ ├── Constants.cs │ └── Commit │ │ └── Simple │ │ └── DeleteTest.cs │ ├── Oracle │ ├── Query │ │ └── Simple │ │ │ ├── SqlQueryTest.cs │ │ │ └── SingleEntityTest.cs │ ├── Commit │ │ └── Simple │ │ │ ├── DeleteTest.cs │ │ │ └── UpdatePropertysTest.cs │ └── Constants.cs │ ├── PostgreSQL │ ├── Query │ │ ├── Simple │ │ │ ├── SqlQueryTest.cs │ │ │ └── SingleEntityTest.cs │ │ └── Inherit │ │ │ ├── SqlQueryTest.cs │ │ │ └── SingleEntityTest.cs │ ├── Constants.cs │ └── Commit │ │ └── Simple │ │ └── DeleteTest.cs │ ├── Constants·.cs │ ├── Core │ ├── Constants.cs │ ├── Query │ │ ├── Simple │ │ │ └── SqlQueryTest.cs │ │ └── Inherit │ │ │ └── SqlQueryTest.cs │ └── FunctionTest.cs │ ├── Common │ ├── GeneratedGuidAttribute.cs │ └── GeneratedDateTimeAttribute.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── packages.config │ └── Firebird │ └── Constants.cs ├── src └── Caredev.Mego │ ├── DataAnnotations │ ├── IColumnAnnotation.cs │ ├── IConcurrencyCheck.cs │ ├── KeyAttribute.cs │ ├── NotMappedAttribute.cs │ ├── ConcurrencyCheckAttribute.cs │ ├── EObjectRelationMode.cs │ ├── NullableAttribute.cs │ ├── DefaultAttribute.cs │ ├── StringAttribute.cs │ ├── GeneratedIgnoreAttribute.cs │ ├── ComputedAttribute.cs │ ├── GeneratedValueAttribute.cs │ ├── PrecisionAttribute.cs │ ├── GeneratedValueBaseAttribute.cs │ ├── LengthAttribute.cs │ ├── GeneratedExpressionAttribute.cs │ ├── RelationActionAttribute.cs │ ├── GeneratedMemoryValueAttribute.cs │ ├── IdentityAttribute.cs │ ├── ColumnAttribute.cs │ ├── InversePropertyAttribute.cs │ └── DbFunctionAttribute.cs │ ├── DbCustomMembers.cs │ ├── IContextContent.cs │ ├── Resolve │ ├── Outputs │ │ ├── IOutputContent.cs │ │ ├── OutputInfoBase.cs │ │ ├── ISingleOutput.cs │ │ ├── IMultiOutput.cs │ │ ├── EOutputType.cs │ │ ├── EObjectOutputOption.cs │ │ ├── GroupCollectionImpl.cs │ │ ├── OutputContentObject.cs │ │ ├── SingleValueOutputInfo.cs │ │ └── MultiValueOutputInfo.cs │ ├── Expressions │ │ ├── IDbExpression.cs │ │ ├── EOrderKind.cs │ │ ├── IDbDefaultUnitType.cs │ │ ├── EMapFunctionKind.cs │ │ ├── IDbExpandUnitExpression.cs │ │ ├── IDbMemberExpression.cs │ │ ├── IDbUnitItemTypeExpression.cs │ │ ├── IDbUnitTypeExpression.cs │ │ ├── EConnectKind.cs │ │ ├── EUnaryKind.cs │ │ ├── DbDataItemExpression.cs │ │ ├── DbDefaultExpression.cs │ │ ├── DbOriginalObjectExpression.cs │ │ ├── DbItemFunctionExpression.cs │ │ ├── DbScalarFunctionExpression.cs │ │ ├── DbSelectExpression.cs │ │ ├── DbJudgeFunctionExpression.cs │ │ ├── DbUnitItemTypeExpression.cs │ │ ├── DbRetrievalFunctionExpression.cs │ │ ├── DbUnitItemContentExpression.cs │ │ ├── DbMapFunctionExpression.cs │ │ ├── DbAggregateFunctionExpression.cs │ │ ├── DbSetOperationExpression.cs │ │ ├── DbNewExpression.cs │ │ ├── DbUnitObjectContentExpression.cs │ │ ├── DbGroupJoinExpression.cs │ │ ├── DbOrderExpression.cs │ │ ├── DbUnitValueContentExpression.cs │ │ ├── DbConstantExpression.cs │ │ ├── DbJoinKeyPairExpression.cs │ │ ├── DbMemberExpression.cs │ │ ├── DbSetFunctionExpression.cs │ │ ├── DbCrossJoinExpression.cs │ │ ├── DbGroupItemExpression.cs │ │ ├── DbDataSetExpression.cs │ │ ├── DbUnitFunctionExpression.cs │ │ ├── DbGroupSetExpression.cs │ │ ├── DbExpression.cs │ │ ├── DbSetConnectExpression.cs │ │ └── DbUnaryExpression.cs │ ├── ValueGenerates │ │ ├── ValueGenerateIgnore.cs │ │ ├── ValueGenerateIdentity.cs │ │ ├── ValueGenerateBase.cs │ │ ├── ValueGenerateDatabase.cs │ │ ├── IMemoryValueGenerator.cs │ │ ├── EGeneratedPurpose.cs │ │ ├── EGeneratedOption.cs │ │ ├── ValueGenerateExpression.cs │ │ └── ValueGenerateMemory.cs │ ├── Metadatas │ │ ├── IPropertyMetadata.cs │ │ ├── MemberKind.cs │ │ ├── TypeMetadataBase.cs │ │ ├── ForeignPrincipalPair.cs │ │ ├── MemberMetadata.cs │ │ └── CompositeNavigateMetadata.cs │ ├── Providers │ │ ├── MySqlAccessProvider.cs │ │ ├── SqlServerAccessProvider.cs │ │ ├── DB2AccessProvider.cs │ │ ├── PostgreSQLAccessProvider.cs │ │ ├── SQLiteAccessProvider.cs │ │ ├── FirebirdAccessProvider.cs │ │ └── SqlServerCeAccessProvider.cs │ ├── Operates │ │ ├── IInsertReferenceRelation.cs │ │ ├── IConcurrencyCheckOperate.cs │ │ ├── DbDeleteStatementOperate.cs │ │ ├── DbInsertStatementOperate.cs │ │ ├── DbUpdateStatementOperate.cs │ │ ├── IDbSplitObjectsOperate.cs │ │ ├── DbDropObjectOperate.cs │ │ ├── DbObjectIsExsitOperate.cs │ │ ├── DbQueryOperateBase.cs │ │ ├── DbCreateTableOperate.cs │ │ ├── DbRenameObjectOperate.cs │ │ ├── DbMaintenanceOperateBase.cs │ │ ├── DbStatementOperateBase.cs │ │ ├── DbPropertysOperateBase.cs │ │ ├── DbRelationItem.cs │ │ ├── EDatabaseObject.cs │ │ └── DbQueryObjectOperate.cs │ ├── Generators │ │ ├── ECommitValueType.cs │ │ ├── Fragments │ │ │ ├── ESetOperate.cs │ │ │ └── EJoinType.cs │ │ ├── Contents │ │ │ ├── QueryContent.cs │ │ │ ├── MaintenanceContent.cs │ │ │ ├── UpdateContent.cs │ │ │ ├── DeleteContent.cs │ │ │ ├── IContentUnit.cs │ │ │ ├── InheritDeleteContent.cs │ │ │ └── InsertContent.cs │ │ ├── CommitIdentityUnit.cs │ │ ├── CommitExpressionMember.cs │ │ ├── CommitKeyUnit.cs │ │ ├── CommitUnitBase.cs │ │ ├── SqlGeneratorBase.Statement.cs │ │ └── Implement │ │ │ └── ExcelGenerator.cs │ ├── EDbNameKind.cs │ ├── EReferenceAction.cs │ ├── EExecutionMode.cs │ ├── Commands │ │ ├── ECommandExecuteMode.cs │ │ └── ICustomCommand.cs │ ├── IPropertyValueLoader.cs │ ├── ValueConversion │ │ ├── GuidToStringConverter.cs │ │ ├── GuidToByteArrayConverter.cs │ │ └── BooleanToInt32Converter.cs │ └── IDbSqlGenerator.cs │ ├── IDbSet.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── DbQuery`.cs │ ├── Exceptions │ ├── GeneratorNotFoundException.cs │ ├── GenerateException.cs │ └── DbCommitConcurrencyException.cs │ ├── Common │ └── InheritTypeComparer.cs │ └── DbFunctions.cs └── README.md /icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarefreeXT/Mego/HEAD/icon.jpg -------------------------------------------------------------------------------- /remark.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarefreeXT/Mego/HEAD/remark.txt -------------------------------------------------------------------------------- /MegoPublicKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarefreeXT/Mego/HEAD/MegoPublicKey.snk -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Resources/EmptyAccess2000.mdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarefreeXT/Mego/HEAD/test/Caredev.Mego.Tests/Resources/EmptyAccess2000.mdb -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Resources/EmptyAccess2003.mdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarefreeXT/Mego/HEAD/test/Caredev.Mego.Tests/Resources/EmptyAccess2003.mdb -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Resources/EmptyExcel2003.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarefreeXT/Mego/HEAD/test/Caredev.Mego.Tests/Resources/EmptyExcel2003.xls -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Resources/EmptyExcel2010.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarefreeXT/Mego/HEAD/test/Caredev.Mego.Tests/Resources/EmptyExcel2010.xlsx -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Resources/EmptyAccess2010.accdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarefreeXT/Mego/HEAD/test/Caredev.Mego.Tests/Resources/EmptyAccess2010.accdb -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/MySql/FunctionTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core 2 | { 3 | public partial class FunctionTest 4 | { 5 | private const string CustomFunctionTestSql = 6 | @"SELECT 7 | a.`Id`, 8 | a.`Name`, 9 | ABS(a.`Id`) AS `AbsId` 10 | FROM `customers` AS a;"; 11 | } 12 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SqlServer/FunctionTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core 2 | { 3 | public partial class FunctionTest 4 | { 5 | private const string CustomFunctionTestSql = 6 | @"SELECT a.[Id] , 7 | a.[Name] , 8 | ABS(a.[Id]) AS [AbsId] 9 | FROM [dbo].[Customers] AS a;"; 10 | } 11 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Access/Query/Simple/SqlQueryTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SqlQueryTest 4 | { 5 | private const string SqlQueryValueTestSql = @"SELECT Id FROM Products"; 6 | 7 | private const string SqlQueryCollectionTestSql = @"SELECT Id ,Code ,Name ,Category ,IsValid FROM Products"; 8 | } 9 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Excel/Query/Simple/SqlQueryTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SqlQueryTest 4 | { 5 | private const string SqlQueryValueTestSql = @"SELECT Id FROM Products"; 6 | 7 | private const string SqlQueryCollectionTestSql = @"SELECT Id ,Code ,Name ,Category ,IsValid FROM Products"; 8 | } 9 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SqlServerCe/Query/Simple/SqlQueryTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SqlQueryTest 4 | { 5 | private const string SqlQueryValueTestSql = @"SELECT Id FROM Products"; 6 | 7 | private const string SqlQueryCollectionTestSql = @"SELECT Id ,Code ,Name ,Category ,IsValid FROM Products"; 8 | } 9 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/MySql/Query/Simple/SqlQueryTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SqlQueryTest 4 | { 5 | private const string SqlQueryValueTestSql = @"SELECT `Id` FROM `Products`"; 6 | 7 | private const string SqlQueryCollectionTestSql = @"SELECT `Id` ,`Code` ,`Name` ,`Category` ,`IsValid` FROM `Products`"; 8 | } 9 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SqlServer/Query/Simple/SqlQueryTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SqlQueryTest 4 | { 5 | private const string SqlQueryValueTestSql = @"SELECT Id FROM dbo.Products"; 6 | 7 | private const string SqlQueryCollectionTestSql = @"SELECT Id ,Code ,Name ,Category ,IsValid FROM dbo.Products"; 8 | } 9 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SQLite/Query/Simple/SqlQueryTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SqlQueryTest 4 | { 5 | private const string SqlQueryValueTestSql = @"SELECT [Id] FROM [Products]"; 6 | 7 | private const string SqlQueryCollectionTestSql = @"SELECT [Id] ,[Code] ,[Name] ,[Category] ,[IsValid] FROM [Products]"; 8 | } 9 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Oracle/Query/Simple/SqlQueryTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SqlQueryTest 4 | { 5 | private const string SqlQueryValueTestSql = @"SELECT ""Id"" FROM ""SIMPLE"".""Products"""; 6 | 7 | private const string SqlQueryCollectionTestSql = @"SELECT ""Id"" ,""Code"" ,""Name"" ,""Category"" ,""IsValid"" FROM ""SIMPLE"".""Products"""; 8 | } 9 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/PostgreSQL/Query/Simple/SqlQueryTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SqlQueryTest 4 | { 5 | private const string SqlQueryValueTestSql = @"SELECT ""Id"" FROM ""public"".""Products"""; 6 | 7 | private const string SqlQueryCollectionTestSql = @"SELECT ""Id"" ,""Code"" ,""Name"" ,""Category"" ,""IsValid"" FROM ""public"".""Products"""; 8 | } 9 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/IColumnAnnotation.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | /// 7 | /// 数据列特性接口,数据列元数据中附加的属性描述都需要实现该接口。 8 | /// 9 | public interface IColumnAnnotation { } 10 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/IConcurrencyCheck.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | /// 7 | /// 实现该接口的数据列特性,将表示所作用到的数据列将参与乐观并发检查。 8 | /// 9 | public interface IConcurrencyCheck : IColumnAnnotation 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/KeyAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System; 7 | /// 8 | /// 主键特性。 9 | /// 10 | [AttributeUsage(AttributeTargets.Property)] 11 | public class KeyAttribute : Attribute 12 | { 13 | } 14 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Constants·.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Caredev.Mego.Tests 9 | { 10 | internal partial class Constants 11 | { 12 | public const string TestCategoryFoundation = "`Foundation"; 13 | 14 | public const string ConnectionNameSimple = "OrderManageForSqlServer2012"; 15 | 16 | public const string NotSuppored = nameof(NotSuppored); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Caredev.Mego/DbCustomMembers.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego 5 | { 6 | /// 7 | /// 自定义数据库成员,用于协助代码生成。 8 | /// 9 | class DbCustomMembers 10 | { 11 | /// 12 | /// 自定义行索引。 13 | /// 14 | public int CustomRowIndex { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/NotMappedAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System; 7 | /// 8 | /// 通过该特性指定需要排除映射的属性。 9 | /// 10 | [AttributeUsage(AttributeTargets.Property)] 11 | public sealed class NotMappedAttribute : Attribute 12 | { 13 | } 14 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/IContextContent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego 5 | { 6 | /// 7 | /// 实现该接口的对象可以提供当前数据上下文的访问属性。 8 | /// 9 | public interface IContextContent 10 | { 11 | /// 12 | /// 数据上下文对象。 13 | /// 14 | DbContext Context { get; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Outputs/IOutputContent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Outputs 5 | { 6 | /// 7 | /// 输出内容接口。 8 | /// 9 | public interface IOutputContent 10 | { 11 | /// 12 | /// 当前输出内容。 13 | /// 14 | object Content { get; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/MySql/Query/Inherit/SqlQueryTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Inherit 2 | { 3 | public partial class SqlQueryTest 4 | { 5 | private const string SqlQueryValueTestSql = @"SELECT Id FROM ProductBases"; 6 | 7 | private const string SqlQueryCollectionTestSql = 8 | @"SELECT a.Id , 9 | a.Code , 10 | a.Name , 11 | b.Category , 12 | b.IsValid , 13 | b.UpdateDate 14 | FROM ProductBases a 15 | INNER JOIN Products b ON b.Id = a.Id;"; 16 | } 17 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SQLite/Query/Inherit/SqlQueryTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Inherit 2 | { 3 | public partial class SqlQueryTest 4 | { 5 | private const string SqlQueryValueTestSql = @"SELECT Id FROM ProductBases"; 6 | 7 | private const string SqlQueryCollectionTestSql = 8 | @"SELECT a.Id , 9 | a.Code , 10 | a.Name , 11 | b.Category , 12 | b.IsValid , 13 | b.UpdateDate 14 | FROM ProductBases a 15 | INNER JOIN Products b ON b.Id = a.Id;"; 16 | } 17 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/ConcurrencyCheckAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System; 7 | /// 8 | /// 指定属性参与乐观并发检查。 9 | /// 10 | [AttributeUsage(AttributeTargets.Property)] 11 | public class ConcurrencyCheckAttribute : Attribute, IConcurrencyCheck 12 | { 13 | } 14 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Outputs/OutputInfoBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Outputs 5 | { 6 | /// 7 | /// 输出信息基类。 8 | /// 9 | public abstract class OutputInfoBase 10 | { 11 | /// 12 | /// 输出类型。 13 | /// 14 | public abstract EOutputType Type { get; } 15 | } 16 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SqlServer/Query/Inherit/SqlQueryTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Inherit 2 | { 3 | public partial class SqlQueryTest 4 | { 5 | private const string SqlQueryValueTestSql = @"SELECT Id FROM dbo.ProductBases"; 6 | 7 | private const string SqlQueryCollectionTestSql = 8 | @"SELECT a.Id , 9 | a.Code , 10 | a.Name , 11 | b.Category , 12 | b.IsValid , 13 | b.UpdateDate 14 | FROM dbo.ProductBases a 15 | INNER JOIN dbo.Products b ON b.Id = a.Id;"; 16 | } 17 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/PostgreSQL/Query/Inherit/SqlQueryTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Inherit 2 | { 3 | public partial class SqlQueryTest 4 | { 5 | private const string SqlQueryValueTestSql = @"SELECT Id FROM dbo.ProductBases"; 6 | 7 | private const string SqlQueryCollectionTestSql = 8 | @"SELECT a.Id , 9 | a.Code , 10 | a.Name , 11 | b.Category , 12 | b.IsValid , 13 | b.UpdateDate 14 | FROM dbo.ProductBases a 15 | INNER JOIN dbo.Products b ON b.Id = a.Id;"; 16 | } 17 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Core/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Caredev.Mego.Tests 8 | { 9 | internal partial class Constants 10 | { 11 | public readonly static string ConnectionNameInherit = "IOrderManageFor" + TestCategoryRootName; 12 | public readonly static string ConnectionNameSimple = "OrderManageFor" + TestCategoryRootName; 13 | 14 | public const string NotSuppored = nameof(NotSuppored); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/IDbExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 所有数据表达式都需要实现的接口。 8 | /// 9 | public interface IDbExpression 10 | { 11 | /// 12 | /// 数据表达式类型。 13 | /// 14 | EExpressionType ExpressionType { get; } 15 | } 16 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Common/GeneratedGuidAttribute.cs: -------------------------------------------------------------------------------- 1 | using Caredev.Mego.DataAnnotations; 2 | using Caredev.Mego.Resolve.ValueGenerates; 3 | using System; 4 | using System.Linq.Expressions; 5 | namespace Caredev.Mego.Tests.Common 6 | { 7 | public class GeneratedGuidAttribute : GeneratedExpressionAttribute 8 | { 9 | public GeneratedGuidAttribute(EGeneratedPurpose purpose = EGeneratedPurpose.Insert) 10 | : base(purpose) 11 | { 12 | Expression = Expression.Call(null, typeof(Guid).GetMethod(nameof(Guid.NewGuid))); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/ValueGenerates/ValueGenerateIgnore.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.ValueGenerates 5 | { 6 | /// 7 | /// 忽略值生成的对象。 8 | /// 9 | internal sealed class ValueGenerateIgnore : ValueGenerateBase 10 | { 11 | /// 12 | public override EGeneratedOption GeneratedOption => EGeneratedOption.Ignore; 13 | } 14 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Metadatas/IPropertyMetadata.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Metadatas 5 | { 6 | using System.Reflection; 7 | /// 8 | /// 属性元数据接口。 9 | /// 10 | public interface IPropertyMetadata 11 | { 12 | /// 13 | /// 当前元数据成员的CLR描述对象。 14 | /// 15 | PropertyInfo Member { get; } 16 | } 17 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/ValueGenerates/ValueGenerateIdentity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.ValueGenerates 5 | { 6 | /// 7 | /// 标识列值生成对象。 8 | /// 9 | internal sealed class ValueGenerateIdentity : ValueGenerateBase 10 | { 11 | /// 12 | public override EGeneratedOption GeneratedOption => EGeneratedOption.Identity; 13 | } 14 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/ValueGenerates/ValueGenerateBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.ValueGenerates 5 | { 6 | /// 7 | /// 值生成定义基类。 8 | /// 9 | public abstract class ValueGenerateBase 10 | { 11 | /// 12 | /// 当前值生成的选项。 13 | /// 14 | public abstract EGeneratedOption GeneratedOption { get; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/ValueGenerates/ValueGenerateDatabase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.ValueGenerates 5 | { 6 | /// 7 | /// 数据库值生成对象。 8 | /// 9 | internal sealed class ValueGenerateDatabase : ValueGenerateBase 10 | { 11 | /// 12 | public override EGeneratedOption GeneratedOption => EGeneratedOption.Database; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/EOrderKind.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 排序操作种类。 8 | /// 9 | public enum EOrderKind 10 | { 11 | /// 12 | /// 升序。 13 | /// 14 | Ascending, 15 | /// 16 | /// 降序。 17 | /// 18 | Descending 19 | } 20 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Common/GeneratedDateTimeAttribute.cs: -------------------------------------------------------------------------------- 1 | using Caredev.Mego.DataAnnotations; 2 | using Caredev.Mego.Resolve.ValueGenerates; 3 | using System; 4 | using System.Linq.Expressions; 5 | 6 | namespace Caredev.Mego.Tests.Common 7 | { 8 | public class GeneratedDateTimeAttribute : GeneratedExpressionAttribute 9 | { 10 | public GeneratedDateTimeAttribute(EGeneratedPurpose purpose = EGeneratedPurpose.Update) 11 | : base(purpose) 12 | { 13 | Expression = Expression.MakeMemberAccess(null, typeof(DateTime).GetProperty(nameof(DateTime.Now))); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/IDbDefaultUnitType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 该接口声明当前表达式可用于数据连接操作,若连接的数据为空则用该默认值替换空值。 8 | /// 9 | public interface IDbDefaultUnitType : IDbExpression 10 | { 11 | /// 12 | /// 在数据连接操作中数据为空时的默认值。 13 | /// 14 | DbExpression Default { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/EMapFunctionKind.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 函数映射种类。 8 | /// 9 | public enum EMapFunctionKind 10 | { 11 | /// 12 | /// 函数(通常对应到数据库标题函数或存储过程等)。 13 | /// 14 | Function, 15 | /// 16 | /// 过程(通常对应到数据库存储过程)。 17 | /// 18 | Action 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Caredev.Mego/IDbSet.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego 5 | { 6 | using System; 7 | using Caredev.Mego.Resolve; 8 | /// 9 | /// 数据集接口 10 | /// 11 | public interface IDbSet : IContextContent 12 | { 13 | /// 14 | /// 数据库名称对象。 15 | /// 16 | DbName Name { get; } 17 | /// 18 | /// 数据项类型。 19 | /// 20 | Type ClrType { get; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Outputs/ISingleOutput.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Outputs 5 | { 6 | using System.Data.Common; 7 | /// 8 | /// 单个值输出接口。 9 | /// 10 | public interface ISingleOutput 11 | { 12 | /// 13 | /// 获取执行结果。 14 | /// 15 | /// 数据读取器。 16 | /// 执行结果。 17 | object GetResult(DbDataReader reader); 18 | } 19 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Providers/MySqlAccessProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Providers 5 | { 6 | /// 7 | /// 访问Nuget组件:MySql.Data 8 | /// 9 | internal class MySqlAccessProvider : DbAccessProvider 10 | { 11 | /// 12 | public override string ProviderName => "MySql.Data.MySqlClient"; 13 | /// 14 | public override EExecutionMode ExecutionMode => EExecutionMode.MergeOperations; 15 | } 16 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/IInsertReferenceRelation.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | using System.Collections.Generic; 7 | /// 8 | /// 当添加数据和关系存在关联时,系统会自动同时提交相关操作, 9 | /// 该接口用于在插入操作对象中声明同时提交的关系操作对象集合。 10 | /// 11 | internal interface IInsertReferenceRelation 12 | { 13 | /// 14 | /// 插入数据时同时提交的关系数据。 15 | /// 16 | ICollection Relations { get; } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Providers/SqlServerAccessProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Providers 5 | { 6 | /// 7 | /// SQL Server 数据访问提供程序。 8 | /// 9 | internal class SqlServerAccessProvider : DbAccessProvider 10 | { 11 | /// 12 | public override string ProviderName => "System.Data.SqlClient"; 13 | /// 14 | public override EExecutionMode ExecutionMode => EExecutionMode.MergeOperations; 15 | } 16 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Providers/DB2AccessProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Providers 5 | { 6 | using System; 7 | /// 8 | /// 访问Nuget组件:IBM.Data.DB2 9 | /// 10 | internal class DB2AccessProvider : DbAccessProvider 11 | { 12 | /// 13 | public override string ProviderName => "IBM.Data.DB2"; 14 | /// 15 | public override EExecutionMode ExecutionMode => throw new NotImplementedException(); 16 | } 17 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/IDbExpandUnitExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System.Collections.Generic; 7 | /// 8 | /// 可展开的数据单元表达式,实现该接口的数据单元可以显示声明获取复 9 | /// 杂对象或集合属性,常用于数据查核的 Include 操作。 10 | /// 11 | public interface IDbExpandUnitExpression : IDbUnitTypeExpression 12 | { 13 | /// 14 | /// 需要展开属性表达式集合。 15 | /// 16 | IList ExpandItems { get; } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Metadatas/MemberKind.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Metadatas 5 | { 6 | /// 7 | /// 成员种类。 8 | /// 9 | public enum MemberKind 10 | { 11 | /// 12 | /// 基元值成员。 13 | /// 14 | Primary = 1, 15 | /// 16 | /// 对象成员。 17 | /// 18 | Object = 2, 19 | /// 20 | /// 集合成员。 21 | /// 22 | Collection = 3 23 | } 24 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/IConcurrencyCheckOperate.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | /// 7 | /// 并发检查操作接口。 8 | /// 9 | internal interface IConcurrencyCheckOperate : IDbSplitObjectsOperate 10 | { 11 | /// 12 | /// 当前操作是否需要并发检查。 13 | /// 14 | bool NeedCheck { get; } 15 | /// 16 | /// 用于并发检查的期望数量。 17 | /// 18 | int ExpectCount { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/ECommitValueType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators 5 | { 6 | /// 7 | /// 值类型。 8 | /// 9 | public enum ECommitValueType 10 | { 11 | /// 12 | /// 常量。 13 | /// 14 | Constant = 0, 15 | /// 16 | /// 数据库生成。 17 | /// 18 | Database = 1, 19 | /// 20 | /// 表达式创建。 21 | /// 22 | Expression = 2 23 | } 24 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Outputs/IMultiOutput.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Outputs 5 | { 6 | using System.Collections.Generic; 7 | using System.Data.Common; 8 | /// 9 | /// 多值输出对象接口。 10 | /// 11 | public interface IMultiOutput 12 | { 13 | /// 14 | /// 获取执行结果。 15 | /// 16 | /// 数据读取器。 17 | /// 执行结果。 18 | IEnumerable GetResult(DbDataReader reader); 19 | } 20 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/IDbMemberExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System.Reflection; 7 | /// 8 | /// 表示访问成员表达式。 9 | /// 10 | public interface IDbMemberExpression : IDbExpression 11 | { 12 | /// 13 | /// 访问的目标表式。 14 | /// 15 | DbExpression Expression { get; } 16 | /// 17 | /// 访问的成员信息对象。 18 | /// 19 | MemberInfo Member { get; } 20 | } 21 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/IDbUnitItemTypeExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System; 7 | /// 8 | /// 该接口表示集合查询表达式中的单个元素。 9 | /// 10 | public interface IDbUnitItemTypeExpression : IDbExpression 11 | { 12 | /// 13 | /// 对应元素的CLR类型。 14 | /// 15 | Type ClrType { get; } 16 | /// 17 | /// 当前所对应的集合查询表达式。 18 | /// 19 | IDbUnitTypeExpression Unit { get; } 20 | } 21 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Caredev.Mego.Tests")] 6 | [assembly: AssemblyDescription("")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany("")] 9 | [assembly: AssemblyProduct("Caredev.Mego.Tests")] 10 | [assembly: AssemblyCopyright("Copyright © 2017")] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] 13 | 14 | [assembly: ComVisible(false)] 15 | 16 | [assembly: Guid("f571c1db-8520-4037-a771-a90a9b8e6da6")] 17 | 18 | // [assembly: AssemblyVersion("1.0.*")] 19 | [assembly: AssemblyVersion("1.0.0.0")] 20 | [assembly: AssemblyFileVersion("1.0.0.0")] 21 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/IDbUnitTypeExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System; 7 | /// 8 | /// 表示一个单元类型表达式的接口(本系统统一将集合类型表达式称为单元)。 9 | /// 10 | public interface IDbUnitTypeExpression : IDbExpression 11 | { 12 | /// 13 | /// 数据项CLR类型。 14 | /// 15 | Type ClrType { get; } 16 | /// 17 | /// 当前集合中元素所对应的项表达式。 18 | /// 19 | DbUnitItemTypeExpression Item { get; } 20 | } 21 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/EDbNameKind.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve 5 | { 6 | /// 7 | /// 数据库名称种类。 8 | /// 9 | public enum EDbNameKind 10 | { 11 | /// 12 | /// 架构名加名称组合成的名称,两种都会以安全名称的形式输出,例如[obj].[Customer]。 13 | /// 14 | NameSchema, 15 | /// 16 | /// 仅名称,以安全名称的形式输出,例如[Customer]。 17 | /// 18 | Name, 19 | /// 20 | /// 常量名称,直接输出指定的名称,例如#temp1。 21 | /// 22 | Contact 23 | } 24 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Providers/PostgreSQLAccessProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Providers 5 | { 6 | /// 7 | /// 访问Nuget组件:Npgsql 8 | /// 9 | internal class PostgreSQLAccessProvider : DbAccessProvider 10 | { 11 | /// 12 | public override bool SupportDistributedTransaction => false; 13 | /// 14 | public override string ProviderName => "Npgsql"; 15 | /// 16 | public override EExecutionMode ExecutionMode => EExecutionMode.MergeOperations; 17 | } 18 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/ValueGenerates/IMemoryValueGenerator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.ValueGenerates 5 | { 6 | using System; 7 | /// 8 | /// 内存值生成器接口。 9 | /// 10 | public interface IMemoryValueGenerator 11 | { 12 | /// 13 | /// 获取生成的值。 14 | /// 15 | /// 当前操作数据对象。 16 | /// 生成值的数据类型。 17 | /// 生成后的值,该值的类型必须是ADO支持或兼容的数据类型。 18 | object NextValue(object item, Type targetType); 19 | } 20 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Providers/SQLiteAccessProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Providers 5 | { 6 | /// 7 | /// 访问Nuget组件: System.Data.SQLite.Core 8 | /// 9 | internal class SQLiteAccessProvider : DbAccessProvider 10 | { 11 | /// 12 | public override bool IsExclusive => true; 13 | /// 14 | public override string ProviderName => "System.Data.SQLite"; 15 | /// 16 | public override EExecutionMode ExecutionMode => EExecutionMode.MergeOperations; 17 | } 18 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/ValueGenerates/EGeneratedPurpose.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.ValueGenerates 5 | { 6 | using System; 7 | /// 8 | /// 值生成目的。 9 | /// 10 | [Flags] 11 | public enum EGeneratedPurpose 12 | { 13 | /// 14 | /// 插入时生成。 15 | /// 16 | Insert = 1, 17 | /// 18 | /// 更新时生成。 19 | /// 20 | Update = 2, 21 | /// 22 | /// 插入或更新时生成。 23 | /// 24 | InsertUpdate = 3 25 | } 26 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Outputs/EOutputType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Outputs 5 | { 6 | /// 7 | /// 输出类型。 8 | /// 9 | public enum EOutputType 10 | { 11 | /// 12 | /// 单个值。 13 | /// 14 | SingleValue, 15 | /// 16 | /// 多个值。 17 | /// 18 | MultiValue, 19 | /// 20 | /// 对象。 21 | /// 22 | Object, 23 | /// 24 | /// 集合。 25 | /// 26 | Collection 27 | } 28 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/EReferenceAction.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve 5 | { 6 | /// 7 | /// 数据关系的引用行为。 8 | /// 9 | public enum EReferenceAction 10 | { 11 | /// 12 | /// 级联删除。 13 | /// 14 | Cascade, 15 | /// 16 | /// 设置为空。 17 | /// 18 | SetNull, 19 | /// 20 | /// 设置为默认值。 21 | /// 22 | SetDefault, 23 | /// 24 | /// 不执行任何操作。 25 | /// 26 | NoAction, 27 | } 28 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/MySql/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Caredev.Mego.Tests 8 | { 9 | internal partial class Constants 10 | { 11 | public const string TestCategoryRootName = "MySql55"; 12 | 13 | public static Models.Simple.OrderManageEntities CreateSimpleContext(bool isinitial = false) 14 | { 15 | return new Models.Simple.OrderManageEntities(Constants.ConnectionNameSimple); 16 | } 17 | 18 | public static Models.Inherit.OrderManageEntities CreateInheritContext(bool isinitial = false) 19 | { 20 | return new Models.Inherit.OrderManageEntities(Constants.ConnectionNameInherit); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/Fragments/ESetOperate.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators.Fragments 5 | { 6 | /// 7 | /// 数据集操作。 8 | /// 9 | public enum ESetOperate 10 | { 11 | /// 12 | /// 连接。 13 | /// 14 | Concat, 15 | /// 16 | /// 合并。 17 | /// 18 | Union, 19 | /// 20 | /// 差集。 21 | /// 22 | Except, 23 | /// 24 | /// 交集。 25 | /// 26 | Intersect 27 | } 28 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SQLite/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Caredev.Mego.Tests 8 | { 9 | internal partial class Constants 10 | { 11 | public const string TestCategoryRootName = "SQLite3"; 12 | 13 | public static Models.Simple.OrderManageEntities CreateSimpleContext(bool isinitial = false) 14 | { 15 | return new Models.Simple.OrderManageEntities(Constants.ConnectionNameSimple); 16 | } 17 | 18 | public static Models.Inherit.OrderManageEntities CreateInheritContext(bool isinitial = false) 19 | { 20 | return new Models.Inherit.OrderManageEntities(Constants.ConnectionNameInherit); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/EConnectKind.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 数据集连接操作各类。 8 | /// 9 | public enum EConnectKind 10 | { 11 | /// 12 | /// 并集。 13 | /// 14 | Union = 1, 15 | /// 16 | /// 交集 17 | /// 18 | Intersect = 2, 19 | /// 20 | /// 排除。 21 | /// 22 | Except = 3, 23 | /// 24 | /// 连接。 25 | /// 26 | Concat = 4, 27 | } 28 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Access/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Caredev.Mego.Tests 8 | { 9 | internal partial class Constants 10 | { 11 | public const string TestCategoryRootName = "Access2003"; 12 | 13 | public static Models.Simple.OrderManageEntities CreateSimpleContext(bool isinitial = false) 14 | { 15 | return new Models.Simple.OrderManageEntities(Constants.ConnectionNameSimple); 16 | } 17 | 18 | public static Models.Inherit.OrderManageEntities CreateInheritContext(bool isinitial = false) 19 | { 20 | return new Models.Inherit.OrderManageEntities(Constants.ConnectionNameInherit); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Firebird/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Caredev.Mego.Tests 8 | { 9 | internal partial class Constants 10 | { 11 | public const string TestCategoryRootName = "Firebird25"; 12 | 13 | public static Models.Simple.OrderManageEntities CreateSimpleContext(bool isinitial = false) 14 | { 15 | return new Models.Simple.OrderManageEntities(Constants.ConnectionNameSimple); 16 | } 17 | 18 | public static Models.Inherit.OrderManageEntities CreateInheritContext(bool isinitial = false) 19 | { 20 | return new Models.Inherit.OrderManageEntities(Constants.ConnectionNameInherit); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SqlServerCe/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Caredev.Mego.Tests 8 | { 9 | internal partial class Constants 10 | { 11 | public const string TestCategoryRootName = "SqlServerCe40"; 12 | 13 | public static Models.Simple.OrderManageEntities CreateSimpleContext(bool isinitial = false) 14 | { 15 | return new Models.Simple.OrderManageEntities(Constants.ConnectionNameSimple); 16 | } 17 | 18 | public static Models.Inherit.OrderManageEntities CreateInheritContext(bool isinitial = false) 19 | { 20 | return new Models.Inherit.OrderManageEntities(Constants.ConnectionNameInherit); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/EUnaryKind.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 一元操作符种类。 8 | /// 9 | public enum EUnaryKind 10 | { 11 | /// 12 | /// 一元正运算操作。 13 | /// 14 | UnaryPlus, 15 | /// 16 | /// 算术求反运算操作。 17 | /// 18 | Negate, 19 | /// 20 | /// 按位求补运算操作。 21 | /// 22 | Not, 23 | /// 24 | /// 类型转换运算操作。 25 | /// 26 | Convert 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/PostgreSQL/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Caredev.Mego.Tests 8 | { 9 | internal partial class Constants 10 | { 11 | public const string TestCategoryRootName = "PostgreSQL93"; 12 | 13 | public static Models.Simple.OrderManageEntities CreateSimpleContext(bool isinitial = false) 14 | { 15 | return new Models.Simple.OrderManageEntities(Constants.ConnectionNameSimple); 16 | } 17 | 18 | public static Models.Inherit.OrderManageEntities CreateInheritContext(bool isinitial = false) 19 | { 20 | return new Models.Inherit.OrderManageEntities(Constants.ConnectionNameInherit); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/EExecutionMode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve 5 | { 6 | /// 7 | /// ADO.NET命令对象的执行模式,由于受限于具体的ADO.NET实现,区别不 8 | /// 同数据源的执行命令的方式。 9 | /// 10 | public enum EExecutionMode 11 | { 12 | /// 13 | /// 合并操作模式,一次可以执行任意数量的语句。 14 | /// 15 | MergeOperations, 16 | /// 17 | /// 单个操作模式,一次可以执行一个操作相关的语句或语句块。 18 | /// 19 | SingleOperation, 20 | /// 21 | /// 单语句模式,一次只能执行一条语句。 22 | /// 23 | SingleStatement, 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/EObjectRelationMode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | /// 7 | /// 对象关系模式。 8 | /// 9 | public enum EObjectRelationMode 10 | { 11 | /// 12 | /// 未设置。 13 | /// 14 | None = 0, 15 | /// 16 | /// 允许为空。 17 | /// 18 | Nullable = 1, 19 | /// 20 | /// 必须关系。 21 | /// 22 | Required = 2, 23 | /// 24 | /// 关系主体。 25 | /// 26 | Principal = 3 27 | } 28 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | using System.Reflection; 5 | using System.Runtime.CompilerServices; 6 | using System.Runtime.InteropServices; 7 | 8 | [assembly: AssemblyTrademark("")] 9 | [assembly: AssemblyCulture("")] 10 | // 将 ComVisible 设置为 false 会使此程序集中的类型 11 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 12 | //请将此类型的 ComVisible 特性设置为 true。 13 | [assembly: ComVisible(false)] 14 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 15 | [assembly: Guid("f7cd97dc-8e1e-4dbc-b7b7-c2ff42dc6a8a")] 16 | 17 | #if RELEASE 18 | [assembly: AssemblyKeyName("VS_KEY_MEGO20150825")] 19 | #else 20 | [assembly: InternalsVisibleTo("Caredev.Mego.Tests")] 21 | #endif -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Providers/FirebirdAccessProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Providers 5 | { 6 | /// 7 | /// 访问Nuget组件: 8 | /// 9 | internal class FirebirdAccessProvider : DbAccessProvider 10 | { 11 | /// 12 | public override string ProviderName => "FirebirdSql.Data.FirebirdClient"; 13 | /// 14 | public override EExecutionMode ExecutionMode => EExecutionMode.SingleOperation; 15 | /// 16 | protected override string VersionPattern => @"Firebird\s+(?
\d{1,2})\.(?\d{1,2})"; 17 | } 18 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Commands/ECommandExecuteMode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Commands 5 | { 6 | using System; 7 | using Caredev.Mego.Resolve.Operates; 8 | /// 9 | /// 命令执行模式。 10 | /// 11 | [Flags] 12 | public enum ECommandExecuteMode 13 | { 14 | /// 15 | /// 默认执行模式。 16 | /// 17 | Simple = 0x01, 18 | /// 19 | /// 按分号分割语句执行。 20 | /// 21 | Split = 0x02, 22 | /// 23 | /// 对于提交操作的数据,使用循环方式执行。 24 | /// 25 | Loop = 0x03 26 | } 27 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbDataItemExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System; 7 | /// 8 | /// 数据项表达式,由成员元素表达式。 9 | /// 10 | public class DbDataItemExpression : DbUnitItemTypeExpression 11 | { 12 | /// 13 | /// 创建数据项表达式。 14 | /// 15 | /// 16 | public DbDataItemExpression(Type type) : base(type) 17 | { 18 | } 19 | /// 20 | public override EExpressionType ExpressionType => EExpressionType.DataItem; 21 | } 22 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/NullableAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System; 7 | /// 8 | /// 可为空特性。 9 | /// 10 | [AttributeUsage(AttributeTargets.Property)] 11 | public class NullableAttribute : Attribute, IColumnAnnotation 12 | { 13 | /// 14 | /// 创建可为空特性。 15 | /// 16 | /// 17 | public NullableAttribute(bool value) 18 | { 19 | Value = value; 20 | } 21 | /// 22 | /// 可为空值。 23 | /// 24 | public bool Value { get; } 25 | } 26 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Outputs/EObjectOutputOption.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Outputs 5 | { 6 | /// 7 | /// 对象输出选项,用于约束对象输出结果是否合法。 8 | /// 9 | public enum EObjectOutputOption : int 10 | { 11 | /// 12 | /// 只返回一个结果。 13 | /// 14 | One = 1, 15 | /// 16 | /// 只返回零个或一个结果。 17 | /// 18 | ZeroOrOne = 0, 19 | /// 20 | /// 有且仅有一个结果。 21 | /// 22 | OnlyOne = 2, 23 | /// 24 | /// 没有结果或有且仅有一个结果。 25 | /// 26 | ZeroOrOnlyOne = 3 27 | } 28 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Outputs/GroupCollectionImpl.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Outputs 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Text; 10 | /// 11 | /// 实现接口,输出分组集合对象。 12 | /// 13 | /// 主键类型。 14 | /// 分组成员类型。 15 | internal class GroupCollectionImpl : HashSet, IGrouping 16 | { 17 | /// 18 | /// 主键类型。 19 | /// 20 | public TKey Key { get; } 21 | } 22 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/DefaultAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System; 7 | /// 8 | /// 数据列默认值。 9 | /// 10 | [AttributeUsage(AttributeTargets.Property)] 11 | public class DefaultAttribute : Attribute, IColumnAnnotation 12 | { 13 | /// 14 | /// 创建默认值特性。 15 | /// 16 | /// 默认值内容。 17 | public DefaultAttribute(string content) 18 | { 19 | Content = content; 20 | } 21 | /// 22 | /// 默认值内容。 23 | /// 24 | public string Content { get; } 25 | } 26 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SqlServerCe/Commit/Simple/DeleteTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Commit.Simple 2 | { 3 | public partial class DeleteTest 4 | { 5 | private const string DeleteSingleTestSql = 6 | @"DELETE [OrderDetails] 7 | WHERE [Id] = @p0"; 8 | 9 | private const string DeleteMultiForKeyTestSql = 10 | @"DELETE [OrderDetails] 11 | WHERE [Id] = @p0"; 12 | 13 | private const string DeleteMultiForKeysTestSql = 14 | @"DELETE [Warehouses] 15 | WHERE [Id] = @p0 16 | AND [Number] = @p1"; 17 | 18 | private const string DeleteStatementForExpressionTestSql = 19 | @"DELETE [Warehouses] 20 | WHERE [Id] > @p0"; 21 | 22 | private const string DeleteStatementForQueryTestSql = 23 | @"DELETE a 24 | FROM [Warehouses] AS a 25 | CROSS JOIN [Customers] AS b 26 | WHERE a.[Id] > b.[Id] 27 | AND a.[Number] > @p0;"; 28 | } 29 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/Fragments/EJoinType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators.Fragments 5 | { 6 | /// 7 | /// 关系数据库对象连接类型。 8 | /// 9 | public enum EJoinType 10 | { 11 | /// 12 | /// 交叉连接。 13 | /// 14 | CrossJoin, 15 | /// 16 | /// 内连接。 17 | /// 18 | InnerJoin, 19 | /// 20 | /// 左外连接。 21 | /// 22 | LeftJoin, 23 | /// 24 | /// 右外连接。 25 | /// 26 | RightJoin, 27 | /// 28 | /// 全外连接。 29 | /// 30 | FullJoin, 31 | } 32 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SqlServer/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Caredev.Mego.Tests 8 | { 9 | internal partial class Constants 10 | { 11 | #if SQLSERVER2012 12 | public const string TestCategoryRootName = "SqlServer2012"; 13 | #else 14 | public const string TestCategoryRootName = "SqlServer2005"; 15 | #endif 16 | 17 | internal static Models.Simple.OrderManageEntities CreateSimpleContext(bool isinitial = false) 18 | { 19 | return new Models.Simple.OrderManageEntities(Constants.ConnectionNameSimple); 20 | } 21 | 22 | internal static Models.Inherit.OrderManageEntities CreateInheritContext(bool isinitial = false) 23 | { 24 | return new Models.Inherit.OrderManageEntities(Constants.ConnectionNameInherit); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Access/Commit/Simple/DeleteTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Commit.Simple 2 | { 3 | public partial class DeleteTest 4 | { 5 | private const string DeleteSingleTestSql = 6 | @"DELETE FROM [OrderDetails] AS a 7 | WHERE a.[Id] = @p0"; 8 | 9 | private const string DeleteMultiForKeyTestSql = 10 | @"DELETE FROM [OrderDetails] AS a 11 | WHERE a.[Id] = @p0"; 12 | 13 | private const string DeleteMultiForKeysTestSql = 14 | @"DELETE FROM [Warehouses] AS a 15 | WHERE a.[Id] = @p0 16 | AND a.[Number] = @p1"; 17 | 18 | private const string DeleteStatementForExpressionTestSql = 19 | @"DELETE FROM [Warehouses] AS a 20 | WHERE a.[Id] > @p0"; 21 | 22 | private const string DeleteStatementForQueryTestSql = 23 | @"DELETE a.* 24 | FROM [Warehouses] AS a 25 | CROSS JOIN [Customers] AS b 26 | WHERE a.[Id] > b.[Id] 27 | AND a.[Number] > @p0;"; 28 | } 29 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Outputs/OutputContentObject.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Outputs 5 | { 6 | using System.Collections.Generic; 7 | /// 8 | /// 输出内容项,用于输出对象时产生的中间对象。 9 | /// 10 | public class OutputContentObject : IOutputContent 11 | { 12 | /// 13 | /// 当前输出内容。 14 | /// 15 | public object Content { get; set; } 16 | /// 17 | /// 当前输出的集合成员。 18 | /// 19 | public Dictionary Members 20 | => _Members ?? (_Members = new Dictionary()); 21 | private Dictionary _Members; 22 | } 23 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbDefaultExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System; 7 | /// 8 | /// 默认值表达式。 9 | /// 10 | public class DbDefaultExpression : DbExpression 11 | { 12 | /// 13 | /// 创建默认值表达式。 14 | /// 15 | /// 16 | public DbDefaultExpression(Type type) 17 | { 18 | ClrType = type; 19 | } 20 | /// 21 | /// 当前默认值的CLR类型。 22 | /// 23 | public Type ClrType { get; private set; } 24 | /// 25 | public override EExpressionType ExpressionType => EExpressionType.Default; 26 | } 27 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Outputs/SingleValueOutputInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Outputs 5 | { 6 | using System.Data.Common; 7 | /// 8 | /// 单个值输出信息对象。 9 | /// 10 | public class SingleValueOutputInfo : OutputInfoBase, ISingleOutput 11 | { 12 | /// 13 | public override EOutputType Type => EOutputType.SingleValue; 14 | /// 15 | /// 获取结果。 16 | /// 17 | /// 数据读取对象。 18 | /// 返回读取的对象。 19 | public object GetResult(DbDataReader reader) 20 | { 21 | reader.Read(); 22 | return reader.IsDBNull(0) ? null : reader.GetValue(0); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbOriginalObjectExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 更新数据时获取数据库原始值引用对象表达式。 8 | /// 9 | public class DbOriginalObjectExpression : DbExpression 10 | { 11 | /// 12 | /// 创建原始值对象表达式。 13 | /// 14 | /// 15 | public DbOriginalObjectExpression(DbExpression item) 16 | { 17 | Item = item; 18 | } 19 | /// 20 | /// 数据项对象。 21 | /// 22 | public DbExpression Item { get; } 23 | /// 24 | public override EExpressionType ExpressionType => EExpressionType.OriginalObject; 25 | } 26 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Access/Query/Simple/SingleEntityTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SingleEntityTest 4 | { 5 | private const string QueryAllDataTestSql = 6 | @"SELECT a.[Id] , 7 | a.[Category] , 8 | a.[Code] , 9 | a.[IsValid] , 10 | a.[Name] , 11 | a.[UpdateDate] 12 | FROM [Products] AS a"; 13 | 14 | private const string OrderQueryDataTestSql = 15 | @"SELECT a.[Id] , 16 | a.[Category] , 17 | a.[Code] , 18 | a.[IsValid] , 19 | a.[Name] , 20 | a.[UpdateDate] 21 | FROM [Products] AS a 22 | ORDER BY a.[Category] ASC"; 23 | 24 | private const string QueryFilterContainsTestSql = 25 | @"SELECT a.[Id] , 26 | a.[Category] , 27 | a.[Code] , 28 | a.[IsValid] , 29 | a.[Name] , 30 | a.[UpdateDate] 31 | FROM [Products] AS a 32 | WHERE a.[Id] IN ( @p0, @p1, @p2, @p3 )"; 33 | } 34 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Excel/Query/Simple/SingleEntityTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SingleEntityTest 4 | { 5 | private const string QueryAllDataTestSql = 6 | @"SELECT a.[Id] , 7 | a.[Category] , 8 | a.[Code] , 9 | a.[IsValid] , 10 | a.[Name] , 11 | a.[UpdateDate] 12 | FROM [Products] AS a"; 13 | 14 | private const string OrderQueryDataTestSql = 15 | @"SELECT a.[Id] , 16 | a.[Category] , 17 | a.[Code] , 18 | a.[IsValid] , 19 | a.[Name] , 20 | a.[UpdateDate] 21 | FROM [Products] AS a 22 | ORDER BY a.[Category] ASC"; 23 | 24 | private const string QueryFilterContainsTestSql = 25 | @"SELECT a.[Id] , 26 | a.[Category] , 27 | a.[Code] , 28 | a.[IsValid] , 29 | a.[Name] , 30 | a.[UpdateDate] 31 | FROM [Products] AS a 32 | WHERE a.[Id] IN ( @p0, @p1, @p2, @p3 )"; 33 | } 34 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/MySql/Query/Simple/SingleEntityTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SingleEntityTest 4 | { 5 | private const string QueryAllDataTestSql = 6 | @"SELECT a.`Id` , 7 | a.`Category` , 8 | a.`Code` , 9 | a.`IsValid` , 10 | a.`Name` , 11 | a.`UpdateDate` 12 | FROM `Products` AS a;"; 13 | 14 | private const string OrderQueryDataTestSql = 15 | @"SELECT a.`Id` , 16 | a.`Category` , 17 | a.`Code` , 18 | a.`IsValid` , 19 | a.`Name` , 20 | a.`UpdateDate` 21 | FROM `Products` AS a 22 | ORDER BY a.`Category` ASC;"; 23 | 24 | private const string QueryFilterContainsTestSql = 25 | @"SELECT a.`Id` , 26 | a.`Category` , 27 | a.`Code` , 28 | a.`IsValid` , 29 | a.`Name` , 30 | a.`UpdateDate` 31 | FROM `Products` AS a 32 | WHERE a.`Id` IN ( @p0, @p1, @p2, @p3 );"; 33 | } 34 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SQLite/Query/Simple/SingleEntityTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SingleEntityTest 4 | { 5 | private const string QueryAllDataTestSql = 6 | @"SELECT a.[Id] , 7 | a.[Category] , 8 | a.[Code] , 9 | a.[IsValid] , 10 | a.[Name] , 11 | a.[UpdateDate] 12 | FROM [Products] AS a;"; 13 | 14 | private const string OrderQueryDataTestSql = 15 | @"SELECT a.[Id] , 16 | a.[Category] , 17 | a.[Code] , 18 | a.[IsValid] , 19 | a.[Name] , 20 | a.[UpdateDate] 21 | FROM [Products] AS a 22 | ORDER BY a.[Category] ASC;"; 23 | 24 | private const string QueryFilterContainsTestSql = 25 | @"SELECT a.[Id] , 26 | a.[Category] , 27 | a.[Code] , 28 | a.[IsValid] , 29 | a.[Name] , 30 | a.[UpdateDate] 31 | FROM [Products] AS a 32 | WHERE a.[Id] IN ( @p0, @p1, @p2, @p3 );"; 33 | } 34 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SqlServerCe/Query/Simple/SingleEntityTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SingleEntityTest 4 | { 5 | private const string QueryAllDataTestSql = 6 | @"SELECT a.[Id] , 7 | a.[Category] , 8 | a.[Code] , 9 | a.[IsValid] , 10 | a.[Name] , 11 | a.[UpdateDate] 12 | FROM [Products] AS a"; 13 | 14 | private const string OrderQueryDataTestSql = 15 | @"SELECT a.[Id] , 16 | a.[Category] , 17 | a.[Code] , 18 | a.[IsValid] , 19 | a.[Name] , 20 | a.[UpdateDate] 21 | FROM [Products] AS a 22 | ORDER BY a.[Category] ASC"; 23 | 24 | private const string QueryFilterContainsTestSql = 25 | @"SELECT a.[Id] , 26 | a.[Category] , 27 | a.[Code] , 28 | a.[IsValid] , 29 | a.[Name] , 30 | a.[UpdateDate] 31 | FROM [Products] AS a 32 | WHERE a.[Id] IN ( @p0, @p1, @p2, @p3 )"; 33 | } 34 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/StringAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System; 7 | /// 8 | /// 字符串描述特性。 9 | /// 10 | [AttributeUsage(AttributeTargets.Property)] 11 | public sealed class StringAttribute : LengthAttribute 12 | { 13 | /// 14 | /// 创建字符串描述特性。 15 | /// 16 | /// 字符串长度。 17 | /// 是否固定长度字符串。 18 | public StringAttribute(int length = 0, bool isfixed = false) 19 | : base(length, isfixed) 20 | { 21 | } 22 | /// 23 | /// 字符串是否 Unicode 编码。 24 | /// 25 | public bool IsUnicode { get; set; } = true; 26 | } 27 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SQLite/Commit/Simple/DeleteTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Commit.Simple 2 | { 3 | public partial class DeleteTest 4 | { 5 | private const string DeleteSingleTestSql = 6 | @"DELETE FROM [OrderDetails] 7 | WHERE [Id] = @p0;"; 8 | 9 | private const string DeleteMultiForKeyTestSql = 10 | @"DELETE FROM [OrderDetails] 11 | WHERE [Id] IN ( @p0, @p1, @p2 );"; 12 | 13 | private const string DeleteMultiForKeysTestSql = 14 | @"DELETE FROM [Warehouses] 15 | WHERE [Id] = @p0 AND [Number] = @p0; 16 | DELETE FROM [Warehouses] 17 | WHERE [Id] = @p0 AND [Number] = @p1;"; 18 | 19 | private const string DeleteStatementForExpressionTestSql = 20 | @"DELETE FROM [Warehouses] 21 | WHERE [Id] > @p0;"; 22 | 23 | private const string DeleteStatementForQueryTestSql = 24 | @"DELETE a 25 | FROM [Warehouses] AS a 26 | CROSS JOIN [Customers] AS b 27 | WHERE a.[Id] > b.[Id] 28 | AND a.[Number] > @p0;"; 29 | } 30 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mego 2 | A high performance and powerful ORM framework supporting SQL Server, MySQL, PostgreSQL, Sqlite, SqlCE, Firebird etc.. 3 | 4 | # Installation 5 | For more information, please view our [Wiki](https://github.com/CarefreeXT/Mego/wiki). 6 | ``` 7 | PM> Install-Package Caredev.Mego 8 | ``` 9 | # Support Database 10 | 11 | Database | Version | Provider Name | Inherits 12 | ---------|---------|---------|---------| 13 | SQL Server | 2005,2008,2012+ | System.Data.SqlClient | Yes 14 | MySQL | 5.6,5.7+ | MySql.Data.MySqlClient | Yes 15 | Oracle | 11g+ | Oracle.ManagedDataAccess.Client | Future 16 | PostgreSQL | 9.3+ | Npgsql | Future 17 | SQLite | 3.0+ | System.Data.SQLite | No 18 | SQL Server Compact | 4.0 | System.Data.SqlServerCe | No 19 | Access | 97-2003+ | System.Data.OleDb.Access | No 20 | Excel | 97-2003+ | System.Data.OleDb.Excel | No 21 | 22 | 23 | # License 24 | Copyright © 2018, CarefreeXT. All rights reserved. 25 | 26 | Licensed under the GNU Lesser General Public License v3.0. 27 | 28 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/Contents/QueryContent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators.Contents 5 | { 6 | using Caredev.Mego.Resolve.Operates; 7 | /// 8 | /// 查询操作内容。 9 | /// 10 | public class QueryContent : OperateContentBase 11 | { 12 | /// 13 | /// 创建内容对象。 14 | /// 15 | /// 生成上下文。 16 | /// 操作对象。 17 | internal QueryContent(GenerateContext context, DbQueryOperateBase operate) 18 | : base(context, operate) 19 | { 20 | Query = operate; 21 | } 22 | /// 23 | /// 查询对象。 24 | /// 25 | internal DbQueryOperateBase Query { get; } 26 | } 27 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SqlServer/Query/Simple/SingleEntityTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SingleEntityTest 4 | { 5 | private const string QueryAllDataTestSql = 6 | @"SELECT a.[Id] , 7 | a.[Category] , 8 | a.[Code] , 9 | a.[IsValid] , 10 | a.[Name] , 11 | a.[UpdateDate] 12 | FROM [dbo].[Products] AS a;"; 13 | 14 | private const string OrderQueryDataTestSql = 15 | @"SELECT a.[Id] , 16 | a.[Category] , 17 | a.[Code] , 18 | a.[IsValid] , 19 | a.[Name] , 20 | a.[UpdateDate] 21 | FROM [dbo].[Products] AS a 22 | ORDER BY a.[Category] ASC;"; 23 | 24 | private const string QueryFilterContainsTestSql = 25 | @"SELECT a.[Id] , 26 | a.[Category] , 27 | a.[Code] , 28 | a.[IsValid] , 29 | a.[Name] , 30 | a.[UpdateDate] 31 | FROM [dbo].[Products] AS a 32 | WHERE a.[Id] IN ( @p0, @p1, @p2, @p3 );"; 33 | } 34 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/ValueGenerates/EGeneratedOption.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.ValueGenerates 5 | { 6 | /// 7 | /// 生成选项。 8 | /// 9 | public enum EGeneratedOption : int 10 | { 11 | /// 12 | /// 忽略生成。 13 | /// 14 | Ignore = 0, 15 | /// 16 | /// 使用数据库的标识体系生成值,只有在添加数据时才能使用。 17 | /// 18 | Identity = 1, 19 | /// 20 | /// 由数据库生成值,例如默认值或触发器等数据库行为。 21 | /// 22 | Database = 2, 23 | /// 24 | /// 使用数据库表达式生成值,在数据生成时执行返回标量值的语句表达式来产生相应的值。 25 | /// 26 | Expression = 3, 27 | /// 28 | /// 在内存中生成值。 29 | /// 30 | Memory = 4 31 | } 32 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/GeneratedIgnoreAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using Caredev.Mego.Resolve.ValueGenerates; 7 | using System; 8 | /// 9 | /// 忽略值生成特性。 10 | /// 11 | [AttributeUsage(AttributeTargets.Property)] 12 | public sealed class GeneratedIgnoreAttribute : GeneratedValueBaseAttribute 13 | { 14 | /// 15 | /// 创建忽略值生成特性。 16 | /// 17 | /// 生成时的目的。 18 | public GeneratedIgnoreAttribute(EGeneratedPurpose purpose) 19 | : base(purpose) 20 | { 21 | } 22 | /// 23 | /// 生成选项。 24 | /// 25 | public override EGeneratedOption GeneratedOption => EGeneratedOption.Ignore; 26 | } 27 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbItemFunctionExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System.Reflection; 7 | /// 8 | /// 数据项函数表达式。 9 | /// 10 | public class DbItemFunctionExpression : DbMapFunctionExpression 11 | { 12 | /// 13 | /// 创建数据项函数表达式。 14 | /// 15 | /// 函数CLR描述对象。 16 | /// 函数映射种类。 17 | /// 函数参数。 18 | public DbItemFunctionExpression(MethodInfo func, EMapFunctionKind kind, params DbExpression[] argus) 19 | : base(func, kind, argus) 20 | { } 21 | /// 22 | public override EExpressionType ExpressionType => EExpressionType.ItemFunction; 23 | } 24 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Excel/Constants.cs: -------------------------------------------------------------------------------- 1 | using Caredev.Mego.Resolve.ValueConversion; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Caredev.Mego.Tests 9 | { 10 | internal partial class Constants 11 | { 12 | public const string TestCategoryRootName = "Excel2003"; 13 | 14 | public static Models.Simple.OrderManageEntities CreateSimpleContext(bool isinitial = false) 15 | { 16 | var db = new Models.Simple.OrderManageEntities(Constants.ConnectionNameSimple); 17 | if (!isinitial) 18 | { 19 | db.Configuration.EnableAutoConversionStorageTypes = true; 20 | } 21 | return db; 22 | } 23 | 24 | public static Models.Inherit.OrderManageEntities CreateInheritContext(bool isinitial = false) 25 | { 26 | return new Models.Inherit.OrderManageEntities(Constants.ConnectionNameInherit); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbScalarFunctionExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System.Reflection; 7 | /// 8 | /// 标量函数调用表达式。 9 | /// 10 | public class DbScalarFunctionExpression : DbMapFunctionExpression 11 | { 12 | /// 13 | /// 创建标量函数调用表达式。 14 | /// 15 | /// CLR函数对象。 16 | /// 函数种类。 17 | /// 函数参数。 18 | public DbScalarFunctionExpression(MemberInfo func, EMapFunctionKind kind, params DbExpression[] argus) 19 | : base(func, kind, argus) 20 | { } 21 | /// 22 | public override EExpressionType ExpressionType => EExpressionType.ScalarFunction; 23 | } 24 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbSelectExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System.Linq; 7 | /// 8 | /// SELECT查询表达式。 9 | /// 10 | public class DbSelectExpression : DbSetOperationExpression 11 | { 12 | /// 13 | /// 创建SELECT查询表达式。 14 | /// 15 | /// 源数据单元表达式。 16 | /// 单元数据项CLR类型。 17 | public DbSelectExpression(DbUnitTypeExpression source, DbUnitItemTypeExpression itemType) 18 | : base(typeof(IQueryable<>).MakeGenericType(itemType.ClrType), source, itemType) 19 | { 20 | 21 | } 22 | /// 23 | public override EExpressionType ExpressionType => EExpressionType.Select; 24 | } 25 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/ComputedAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System; 7 | /// 8 | /// 计算列特性。 9 | /// 10 | [AttributeUsage(AttributeTargets.Property)] 11 | public class ComputedAttribute : Attribute, IColumnAnnotation 12 | { 13 | /// 14 | /// 创建计算列特性。 15 | /// 16 | /// 数据库表达式。 17 | public ComputedAttribute(string expression) 18 | { 19 | Expression = expression; 20 | } 21 | /// 22 | /// 数据库计算表达式。 23 | /// 24 | public string Expression { get; } 25 | /// 26 | /// 是否持久化值。 27 | /// 28 | public bool IsPersisted { get; set; } 29 | } 30 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Oracle/Query/Simple/SingleEntityTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SingleEntityTest 4 | { 5 | private const string QueryAllDataTestSql = 6 | @"SELECT a.""Id"" , 7 | a.""Category"" , 8 | a.""Code"" , 9 | a.""IsValid"" , 10 | a.""Name"" , 11 | a.""UpdateDate"" 12 | FROM ""SIMPLE"".""Products"" a"; 13 | 14 | private const string OrderQueryDataTestSql = 15 | @"SELECT a.""Id"" , 16 | a.""Category"" , 17 | a.""Code"" , 18 | a.""IsValid"" , 19 | a.""Name"" , 20 | a.""UpdateDate"" 21 | FROM ""SIMPLE"".""Products"" a 22 | ORDER BY a.""Category"" ASC"; 23 | 24 | private const string QueryFilterContainsTestSql = 25 | @"SELECT a.""Id"" , 26 | a.""Category"" , 27 | a.""Code"" , 28 | a.""IsValid"" , 29 | a.""Name"" , 30 | a.""UpdateDate"" 31 | FROM ""SIMPLE"".""Products"" a 32 | WHERE a.""Id"" IN ( :p0, :p1, :p2, :p3 )"; 33 | } 34 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/Contents/MaintenanceContent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators.Contents 5 | { 6 | using Caredev.Mego.Resolve.Operates; 7 | /// 8 | /// 结构维护内容对象。 9 | /// 10 | public class MaintenanceContent : OperateContentBase 11 | { 12 | /// 13 | /// 创建内容对象。 14 | /// 15 | /// 生成上下文。 16 | /// 操作对象。 17 | internal MaintenanceContent(GenerateContext context, DbMaintenanceOperateBase operate) 18 | : base(context, operate) 19 | { 20 | Maintenance = operate; 21 | } 22 | /// 23 | /// 维护操作对象。 24 | /// 25 | public DbMaintenanceOperateBase Maintenance { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/DbDeleteStatementOperate.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | using System.Linq.Expressions; 7 | /// 8 | /// 数据删除语句操作。 9 | /// 10 | /// 数据类型 11 | internal class DbDeleteStatementOperate : DbStatementOperateBase 12 | where T : class 13 | { 14 | /// 15 | /// 创建数据删除语句操作。 16 | /// 17 | /// 操作目标。 18 | /// 删除表达式。 19 | internal DbDeleteStatementOperate(DbSet target, Expression expression) 20 | : base(target, expression, typeof(T)) 21 | { 22 | } 23 | /// 24 | public override EOperateType Type => EOperateType.DeleteStatement; 25 | } 26 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/DbInsertStatementOperate.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | using System.Linq.Expressions; 7 | /// 8 | /// 数据插入语句操作。 9 | /// 10 | /// 数据类型 11 | internal class DbInsertStatementOperate : DbStatementOperateBase 12 | where T : class 13 | { 14 | /// 15 | /// 创建数据插入语句操作。 16 | /// 17 | /// 操作目标。 18 | /// 插入表达式。 19 | internal DbInsertStatementOperate(DbSet target, Expression expression) 20 | : base(target, expression, typeof(T)) 21 | { 22 | } 23 | /// 24 | public override EOperateType Type => EOperateType.InsertStatement; 25 | } 26 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/GeneratedValueAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using Caredev.Mego.Resolve.ValueGenerates; 7 | using System; 8 | /// 9 | /// 数据库生成值特性。 10 | /// 11 | [AttributeUsage(AttributeTargets.Property)] 12 | public sealed class GeneratedValueAttribute : GeneratedValueBaseAttribute 13 | { 14 | /// 15 | /// 创建数据库生成值特性。 16 | /// 17 | /// 生成目的。 18 | public GeneratedValueAttribute(EGeneratedPurpose purpose = EGeneratedPurpose.Insert) 19 | : base(purpose) 20 | { 21 | } 22 | /// 23 | /// 生成选项。 24 | /// 25 | public override EGeneratedOption GeneratedOption => EGeneratedOption.Database; 26 | } 27 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/DbUpdateStatementOperate.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | using System.Linq.Expressions; 7 | /// 8 | /// 表达式语句更新操作。 9 | /// 10 | /// 11 | internal class DbUpdateStatementOperate : DbStatementOperateBase 12 | where T : class 13 | { 14 | /// 15 | /// 使用指定的表达式创建更新操作。 16 | /// 17 | /// 操作目标。 18 | /// 用于更新的表达式。 19 | internal DbUpdateStatementOperate(DbSet target, Expression expression) 20 | : base(target, expression, typeof(T)) 21 | { 22 | } 23 | /// 24 | public override EOperateType Type => EOperateType.UpdateStatement; 25 | } 26 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbJudgeFunctionExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System.Reflection; 7 | /// 8 | /// 判断函数表达式,例如Any、All等LINQ函数。 9 | /// 10 | public class DbJudgeFunctionExpression : DbSourceFunctionExpression 11 | { 12 | /// 13 | /// 创建判断函数表达式。 14 | /// 15 | /// 源表达式。 16 | /// 函数CLR描述对象。 17 | /// 函数参数。 18 | public DbJudgeFunctionExpression(IDbUnitTypeExpression source, MethodInfo func, params DbExpression[] argus) 19 | : base(source, func, argus) 20 | { } 21 | /// 22 | public override EExpressionType ExpressionType => EExpressionType.JudgeFunction; 23 | } 24 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Metadatas/TypeMetadataBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Metadatas 5 | { 6 | using System; 7 | /// 8 | /// 类型元数据基类。 9 | /// 10 | public abstract class TypeMetadataBase 11 | { 12 | /// 13 | /// 创建类型元数据基类。 14 | /// 15 | /// CLR类型。 16 | /// 元数据引擎。 17 | public TypeMetadataBase(Type itemType, MetadataEngine engine) 18 | { 19 | Engine = engine; 20 | ClrType = itemType; 21 | } 22 | /// 23 | /// CLR类型。 24 | /// 25 | public Type ClrType { get; } 26 | /// 27 | /// 元数据引擎。 28 | /// 29 | public MetadataEngine Engine { get; } 30 | } 31 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/PostgreSQL/Query/Simple/SingleEntityTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | public partial class SingleEntityTest 4 | { 5 | private const string QueryAllDataTestSql = 6 | @"SELECT a.""Id"" , 7 | a.""Category"" , 8 | a.""Code"" , 9 | a.""IsValid"" , 10 | a.""Name"" , 11 | a.""UpdateDate"" 12 | FROM ""public"".""Products"" AS a;"; 13 | 14 | private const string OrderQueryDataTestSql = 15 | @"SELECT a.""Id"" , 16 | a.""Category"" , 17 | a.""Code"" , 18 | a.""IsValid"" , 19 | a.""Name"" , 20 | a.""UpdateDate"" 21 | FROM ""public"".""Products"" AS a 22 | ORDER BY a.""Category"" ASC;"; 23 | 24 | private const string QueryFilterContainsTestSql = 25 | @"SELECT a.""Id"" , 26 | a.""Category"" , 27 | a.""Code"" , 28 | a.""IsValid"" , 29 | a.""Name"" , 30 | a.""UpdateDate"" 31 | FROM ""public"".""Products"" AS a 32 | WHERE a.""Id"" IN ( @p0, @p1, @p2, @p3 );"; 33 | } 34 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbUnitItemTypeExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System; 7 | /// 8 | /// 表示单元表达式中的的单个元素项(简称单元项)。 9 | /// 10 | public abstract class DbUnitItemTypeExpression : DbExpression, IDbUnitItemTypeExpression 11 | { 12 | /// 13 | /// 创建单元项表达式。 14 | /// 15 | /// 数据项的CLR类型。 16 | internal DbUnitItemTypeExpression(Type type) 17 | { 18 | ClrType = type; 19 | } 20 | /// 21 | /// 数据项的CLR类型。 22 | /// 23 | public Type ClrType { get; private set; } 24 | /// 25 | /// 项的单元表达式。 26 | /// 27 | public IDbUnitTypeExpression Unit { get; internal set; } 28 | } 29 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbRetrievalFunctionExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System.Reflection; 7 | /// 8 | /// 集合检索函数表达式,例如First、Single等LINQ函数操作。 9 | /// 10 | public class DbRetrievalFunctionExpression : DbSourceFunctionExpression 11 | { 12 | /// 13 | /// 创建集合检索函数表达式。 14 | /// 15 | /// 16 | /// 17 | /// 18 | public DbRetrievalFunctionExpression(IDbUnitTypeExpression source, MethodInfo func, params DbExpression[] argus) 19 | : base(source, func, argus) 20 | { } 21 | /// 22 | public override EExpressionType ExpressionType => EExpressionType.RetrievalFunction; 23 | } 24 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/CommitIdentityUnit.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators 5 | { 6 | using Caredev.Mego.Resolve.Metadatas; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | /// 11 | /// 带有标识列的提交单元。 12 | /// 13 | public class CommitIdentityUnit : CommitUnitBase 14 | { 15 | /// 16 | /// 创建提交单元。 17 | /// 18 | /// 表元数据。 19 | /// 标识列。 20 | public CommitIdentityUnit(TableMetadata table, CommitMember identity) 21 | : base(table) 22 | { 23 | Identity = identity; 24 | } 25 | /// 26 | /// 标识列。 27 | /// 28 | public CommitMember Identity { get; } 29 | } 30 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/ValueGenerates/ValueGenerateExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.ValueGenerates 5 | { 6 | using System.Linq.Expressions; 7 | /// 8 | /// 表达式值生成对象。 9 | /// 10 | public class ValueGenerateExpression : ValueGenerateBase 11 | { 12 | /// 13 | /// 创建表达式值生成对象。 14 | /// 15 | /// 生成值的表达式。 16 | internal ValueGenerateExpression(Expression expression) 17 | : base() 18 | { 19 | Expression = expression; 20 | } 21 | /// 22 | /// 当前生成值的表达式。 23 | /// 24 | public Expression Expression { get; set; } 25 | /// 26 | public override EGeneratedOption GeneratedOption => EGeneratedOption.Expression; 27 | } 28 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbUnitItemContentExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 数据项内容表达式。 8 | /// 9 | public class DbUnitItemContentExpression : DbUnitItemTypeExpression 10 | { 11 | /// 12 | /// 创建数据项内容表达式。 13 | /// 14 | /// 当前内容表达式。 15 | public DbUnitItemContentExpression(DbUnitItemTypeExpression content) 16 | : base(content.ClrType) 17 | { 18 | Content = content; 19 | } 20 | /// 21 | /// 数据项内容表达式。 22 | /// 23 | public DbUnitItemTypeExpression Content { get; private set; } 24 | /// 25 | public override EExpressionType ExpressionType => EExpressionType.UnitItemContent; 26 | } 27 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbMapFunctionExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System.Reflection; 7 | /// 8 | /// 函数映射表达式。 9 | /// 10 | public abstract class DbMapFunctionExpression : DbFunctionBaseExpression 11 | { 12 | /// 13 | /// 创建函数映射表达式。 14 | /// 15 | /// 函数CLR描述对象。 16 | /// 映射种类。 17 | /// 函数参数。 18 | public DbMapFunctionExpression(MemberInfo func, EMapFunctionKind kind, DbExpression[] argus) 19 | : base(func, argus) 20 | { 21 | Kind = kind; 22 | } 23 | /// 24 | /// 映射种类。 25 | /// 26 | public EMapFunctionKind Kind { get; private set; } 27 | } 28 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbAggregateFunctionExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System.Reflection; 7 | /// 8 | /// 汇总函数表达式。 9 | /// 10 | public class DbAggregateFunctionExpression : DbSourceFunctionExpression 11 | { 12 | /// 13 | /// 创建汇总函数表达式。 14 | /// 15 | /// 源表达式。 16 | /// 函数CLR描述对象。 17 | /// 函数参数。 18 | public DbAggregateFunctionExpression(IDbUnitTypeExpression source, MemberInfo function, params DbExpression[] arguments) 19 | : base(source, function, arguments) 20 | { } 21 | /// 22 | public override EExpressionType ExpressionType => EExpressionType.AggregateFunction; 23 | } 24 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Metadatas/ForeignPrincipalPair.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Metadatas 5 | { 6 | /// 7 | /// 描述关系的主外键对。 8 | /// 9 | public class ForeignPrincipalPair 10 | { 11 | /// 12 | /// 创建主外键对。 13 | /// 14 | /// 外键列元数据。 15 | /// 主键列元数据。 16 | public ForeignPrincipalPair(ColumnMetadata foreign, ColumnMetadata principal) 17 | { 18 | ForeignKey = foreign; 19 | PrincipalKey = principal; 20 | } 21 | /// 22 | /// 外键列元数据。 23 | /// 24 | public ColumnMetadata ForeignKey { get; } 25 | /// 26 | /// 主键列元数据。 27 | /// 28 | public ColumnMetadata PrincipalKey { get; } 29 | } 30 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Commands/ICustomCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Commands 5 | { 6 | using Caredev.Mego.Resolve.Operates; 7 | using System.Data.Common; 8 | /// 9 | /// 自定义命令接口,对于特定场景下数据提供 10 | /// 程序需要指定的数据提交逻辑。 11 | /// 12 | public interface ICustomCommand 13 | { 14 | /// 15 | /// 执行命令。 16 | /// 17 | /// 指定的命令对象。 18 | /// 当前操作对象。 19 | /// 执行后的影响行数。 20 | int Execute(DbCommand command, DbOperateBase operate); 21 | /// 22 | /// 添加普通参数。 23 | /// 24 | /// 值 25 | /// 参数前级 26 | /// 参数名。 27 | string AddParameter(object value, string prefix); 28 | } 29 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbSetOperationExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System; 7 | /// 8 | /// 单元操作表达式基类。 9 | /// 10 | public abstract class DbSetOperationExpression : DbUnitTypeExpression 11 | { 12 | /// 13 | /// 初始化数据集操作。 14 | /// 15 | /// 数据集的元素CLR类型。 16 | /// 操作的单元表达式。 17 | /// 单元项表达式。 18 | public DbSetOperationExpression(Type type, DbUnitTypeExpression source, DbUnitItemTypeExpression itemType) 19 | : base(type, itemType) 20 | { 21 | Source = source; 22 | } 23 | /// 24 | /// 操作的目标数据单元。 25 | /// 26 | public DbUnitTypeExpression Source { get; private set; } 27 | } 28 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/IPropertyValueLoader.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve 5 | { 6 | using System.Reflection; 7 | /// 8 | /// 属性值加载器接口。 9 | /// 10 | public interface IPropertyValueLoader 11 | { 12 | /// 13 | /// 通过指定索引获取值。 14 | /// 15 | /// 索引值。 16 | /// 相应位置的值。 17 | object this[int index] { get; } 18 | /// 19 | /// 加载对象值。 20 | /// 21 | /// 加载的对象。 22 | /// 返回当前对象。 23 | IPropertyValueLoader Load(object item); 24 | /// 25 | /// 根据成员获取所在当前加载器的索引位置。 26 | /// 27 | /// 指定成员。 28 | /// 索引位置。 29 | int IndexOf(MemberInfo member); 30 | } 31 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/PrecisionAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System; 7 | /// 8 | /// 数字列精度特性。 9 | /// 10 | [AttributeUsage(AttributeTargets.Property)] 11 | public sealed class PrecisionAttribute : Attribute, IColumnAnnotation 12 | { 13 | /// 14 | /// 创建精度特性。 15 | /// 16 | /// 精度。 17 | /// 小数位数。 18 | public PrecisionAttribute(byte precision, byte scale = 0) 19 | { 20 | Precision = precision; 21 | Scale = scale; 22 | } 23 | /// 24 | /// 精度。 25 | /// 26 | public byte Precision { get; } 27 | /// 28 | /// 小数位数。 29 | /// 30 | public byte Scale { get; } 31 | } 32 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbNewExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Reflection; 9 | /// 10 | /// 新建对象表达式,通常用于做字段映射。 11 | /// 12 | public class DbNewExpression : DbUnitItemTypeExpression 13 | { 14 | /// 15 | /// 创建新建对象表达式。 16 | /// 17 | /// 18 | public DbNewExpression(Type type) : base(type) 19 | { 20 | Members = new Dictionary(); 21 | } 22 | /// 23 | /// 成员表达式集合。 24 | /// 25 | public Dictionary Members { get; private set; } 26 | /// 27 | public override EExpressionType ExpressionType => EExpressionType.New; 28 | } 29 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/GeneratedValueBaseAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using Caredev.Mego.Resolve.ValueGenerates; 7 | using System; 8 | /// 9 | /// 生成值特性,这也是所有生成值的基类,在一个属性上只能有一个生成值特性。 10 | /// 11 | public abstract class GeneratedValueBaseAttribute : Attribute 12 | { 13 | /// 14 | /// 创建生成值特性。 15 | /// 16 | /// 生成值的目的。 17 | public GeneratedValueBaseAttribute(EGeneratedPurpose purpose) 18 | { 19 | GeneratedPurpose = purpose; 20 | } 21 | /// 22 | /// 值生成目的。 23 | /// 24 | public EGeneratedPurpose GeneratedPurpose { get; } 25 | /// 26 | /// 值生成选项。 27 | /// 28 | public abstract EGeneratedOption GeneratedOption { get; } 29 | } 30 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/IDbSplitObjectsOperate.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | using System; 7 | using System.Collections; 8 | /// 9 | /// 实现该接口的对象操作,当操作的对象过多无法一次性提交时, 10 | /// 可多次分开操作,该接口完成相应操作的数据成员及方法。 11 | /// 12 | internal interface IDbSplitObjectsOperate : IEnumerable 13 | { 14 | /// 15 | /// 在指定函数调用过程中,从指定的索引分割当前操作为指定长度的集合。 16 | /// 17 | /// 开始索引。 18 | /// 操作长度。 19 | /// 执行的操作。 20 | void Split(int index, int length, Action action); 21 | /// 22 | /// 当前操作数量。 23 | /// 24 | int Count { get; } 25 | /// 26 | /// 当前提交每个对象时可能包含的最大参数数量。 27 | /// 28 | int ItemParameterCount { get; } 29 | } 30 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Outputs/MultiValueOutputInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Outputs 5 | { 6 | using System.Collections.Generic; 7 | using System.Data.Common; 8 | /// 9 | /// 多个基元值输出信息对象。 10 | /// 11 | public class MultiValueOutputInfo : OutputInfoBase, IMultiOutput 12 | { 13 | /// 14 | public override EOutputType Type => EOutputType.MultiValue; 15 | /// 16 | /// 获取执行结果。 17 | /// 18 | /// 数据读取器。 19 | /// 多个基元值枚举。 20 | public IEnumerable GetResult(DbDataReader reader) 21 | { 22 | while (reader.Read()) 23 | { 24 | if (!reader.IsDBNull(0)) 25 | { 26 | yield return reader.GetValue(0); 27 | } 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/ValueConversion/GuidToStringConverter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.ValueConversion 5 | { 6 | using System; 7 | using System.Reflection; 8 | /// 9 | /// 转换器。 10 | /// 11 | public class GuidToStringConverter 12 | { 13 | /// 14 | /// 向数据对象转换值。 15 | /// 16 | /// 转换值。 17 | /// 转换结果 18 | public static Guid ConvertToObject(string value) 19 | { 20 | return new Guid(value); 21 | } 22 | /// 23 | /// 向存储转换值。 24 | /// 25 | /// 转换值。 26 | /// 转换结果 27 | public static object ConvertToStorage(Guid value) 28 | { 29 | return value.ToString(); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/LengthAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System; 7 | /// 8 | /// 数据列长度特性。 9 | /// 10 | [AttributeUsage(AttributeTargets.Property)] 11 | public class LengthAttribute : Attribute, IColumnAnnotation 12 | { 13 | /// 14 | /// 创建长度特性。 15 | /// 16 | /// 长度值。 17 | /// 是否固定长度。 18 | public LengthAttribute(int length = 0, bool isfixed = false) 19 | { 20 | Length = length; 21 | IsFixed = isfixed; 22 | } 23 | /// 24 | /// 当前数据列长度,默认为 0 ,如果小于或等于 0 则表示不限长度。 25 | /// 26 | public int Length { get; } 27 | /// 28 | /// 是否固定长度。 29 | /// 30 | public bool IsFixed { get; } 31 | } 32 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/DbDropObjectOperate.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | using System; 7 | /// 8 | /// 删除对象操作。 9 | /// 10 | internal class DbDropObjectOperate : DbMaintenanceOperateBase 11 | { 12 | /// 13 | /// 创建操作。 14 | /// 15 | /// 数据上下文。 16 | /// 相关CLR类型。 17 | /// 当前操作类型。 18 | /// 操作对象名称。 19 | internal DbDropObjectOperate(DbContext context, Type type, EOperateType operateType, DbName name) 20 | : base(context, type ?? typeof(object), name) 21 | { 22 | _Type = operateType; 23 | } 24 | /// 25 | public override EOperateType Type => _Type; 26 | private readonly EOperateType _Type; 27 | } 28 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/ValueConversion/GuidToByteArrayConverter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.ValueConversion 5 | { 6 | using System; 7 | using System.Reflection; 8 | /// 9 | /// 转换器。 10 | /// 11 | public class GuidToByteArrayConverter 12 | { 13 | /// 14 | /// 向数据对象转换值。 15 | /// 16 | /// 转换值。 17 | /// 转换结果 18 | public static Guid ConvertToObject(byte[] value) 19 | { 20 | return new Guid(value); 21 | } 22 | /// 23 | /// 向存储转换值。 24 | /// 25 | /// 转换值。 26 | /// 转换结果 27 | public static object ConvertToStorage(Guid value) 28 | { 29 | return value.ToByteArray(); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Core/Query/Simple/SqlQueryTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Simple 2 | { 3 | using System.Linq; 4 | using Caredev.Mego.Tests.Models.Simple; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | [TestClass, TestCategory(Constants.TestCategoryRootName + ".Query.Simple")] 7 | public partial class SqlQueryTest 8 | { 9 | [TestMethod] 10 | public void SqlQueryValueTest() 11 | { 12 | using (var db = CreateContext()) 13 | { 14 | var data = db.Database.SqlQuery(SqlQueryValueTestSql); 15 | Assert.IsTrue(data.Any(a => a > 0)); 16 | } 17 | } 18 | 19 | [TestMethod] 20 | public void SqlQueryCollectionTest() 21 | { 22 | using (var db = CreateContext()) 23 | { 24 | var data = db.Database.SqlQuery(SqlQueryCollectionTestSql); 25 | Assert.IsTrue(data.Any(a => a.Id > 0)); 26 | } 27 | } 28 | internal OrderManageEntities CreateContext() => Constants.CreateSimpleContext(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Core/Query/Inherit/SqlQueryTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Inherit 2 | { 3 | using System.Linq; 4 | using Caredev.Mego.Tests.Models.Inherit; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | [TestClass, TestCategory(Constants.TestCategoryRootName + ".IQuery.Simple")] 7 | public partial class SqlQueryTest 8 | { 9 | [TestMethod] 10 | public void SqlQueryValueTest() 11 | { 12 | using (var db = CreateContext()) 13 | { 14 | var data = db.Database.SqlQuery(SqlQueryValueTestSql); 15 | Assert.IsTrue(data.Any(a => a > 0)); 16 | } 17 | } 18 | 19 | [TestMethod] 20 | public void SqlQueryCollectionTest() 21 | { 22 | using (var db = CreateContext()) 23 | { 24 | var data = db.Database.SqlQuery(SqlQueryCollectionTestSql); 25 | Assert.IsTrue(data.Any(a => a.Id > 0)); 26 | } 27 | } 28 | internal OrderManageEntities CreateContext() => Constants.CreateInheritContext(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/DbObjectIsExsitOperate.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | using System; 7 | /// 8 | /// 判断数据库对象是否存在操作。 9 | /// 10 | internal class DbObjectIsExsitOperate : DbMaintenanceOperateBase 11 | { 12 | /// 13 | /// 创建操作。 14 | /// 15 | /// 数据上下文。 16 | /// 相关CLR类型。 17 | /// 当前操作类型。 18 | /// 操作对象名称。 19 | internal DbObjectIsExsitOperate(DbContext context, Type type, EOperateType operateType, DbName name) 20 | : base(context, type ?? typeof(object), name) 21 | { 22 | _Type = operateType; 23 | } 24 | /// 25 | public override EOperateType Type => _Type; 26 | private readonly EOperateType _Type; 27 | } 28 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/MySql/Query/Inherit/SingleEntityTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Inherit 2 | { 3 | public partial class SingleEntityTest 4 | { 5 | private const string QueryAllDataTestSql = 6 | @"SELECT a.`Id` , 7 | a.`Code` , 8 | a.`Name` , 9 | b.`Category` , 10 | b.`IsValid` , 11 | b.`UpdateDate` 12 | FROM `ProductBases` AS a 13 | INNER JOIN `Products` AS b ON a.`Id` = b.`Id`;"; 14 | private const string OrderQueryDataTestSql = 15 | @"SELECT a.`Id` , 16 | a.`Code` , 17 | a.`Name` , 18 | b.`Category` , 19 | b.`IsValid` , 20 | b.`UpdateDate` 21 | FROM `ProductBases` AS a 22 | INNER JOIN `Products` AS b ON a.`Id` = b.`Id` 23 | ORDER BY b.`Category` ASC;"; 24 | private const string QueryFilterContainsTestSql = 25 | @"SELECT a.`Id` , 26 | a.`Code` , 27 | a.`Name` , 28 | b.`Category` , 29 | b.`IsValid` , 30 | b.`UpdateDate` 31 | FROM `ProductBases` AS a 32 | INNER JOIN `Products` AS b ON a.`Id` = b.`Id` 33 | WHERE a.`Id` IN ( @p0, @p1, @p2, @p3 );"; 34 | } 35 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Oracle/Commit/Simple/DeleteTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Commit.Simple 2 | { 3 | public partial class DeleteTest 4 | { 5 | private const string DeleteSingleTestSql = 6 | @"DELETE FROM ""SIMPLE"".""OrderDetails"" a 7 | WHERE a.""Id"" = :p0 8 | AND a.""Discount"" = :p1"; 9 | 10 | private const string DeleteMultiForKeyTestSql = 11 | @"DELETE FROM ""SIMPLE"".""OrderDetails"" a 12 | WHERE a.""Id"" = :p0"; 13 | 14 | private const string DeleteMultiForKeysTestSql = 15 | @"DELETE FROM ""SIMPLE"".""Warehouses"" a 16 | WHERE a.""Id"" = :p0 AND a.""Number"" = :p1 AND a.""Address"" = :p2"; 17 | 18 | private const string DeleteStatementForExpressionTestSql = 19 | @"DELETE FROM ""SIMPLE"".""Warehouses"" a 20 | WHERE a.""Id"" > :p0"; 21 | 22 | private const string DeleteStatementForQueryTestSql = 23 | @"DELETE FROM ""SIMPLE"".""Warehouses"" a 24 | WHERE ROWID IN 25 | ( SELECT a.ROWID 26 | FROM ""SIMPLE"".""Warehouses"" a 27 | CROSS JOIN ""SIMPLE"".""Customers"" b 28 | WHERE a.""Id"" > b.""Id"" AND a.""Number"" > :p0 29 | )"; 30 | } 31 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SQLite/Query/Inherit/SingleEntityTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Inherit 2 | { 3 | public partial class SingleEntityTest 4 | { 5 | private const string QueryAllDataTestSql = 6 | @"SELECT a.[Id] , 7 | a.[Code] , 8 | a.[Name] , 9 | b.[Category] , 10 | b.[IsValid] , 11 | b.[UpdateDate] 12 | FROM [ProductBases] AS a 13 | INNER JOIN [Products] AS b ON a.[Id] = b.[Id];"; 14 | private const string OrderQueryDataTestSql = 15 | @"SELECT a.[Id] , 16 | a.[Code] , 17 | a.[Name] , 18 | b.[Category] , 19 | b.[IsValid] , 20 | b.[UpdateDate] 21 | FROM [ProductBases] AS a 22 | INNER JOIN [Products] AS b ON a.[Id] = b.[Id] 23 | ORDER BY b.[Category] ASC;"; 24 | private const string QueryFilterContainsTestSql = 25 | @"SELECT a.[Id] , 26 | a.[Code] , 27 | a.[Name] , 28 | b.[Category] , 29 | b.[IsValid] , 30 | b.[UpdateDate] 31 | FROM [ProductBases] AS a 32 | INNER JOIN [Products] AS b ON a.[Id] = b.[Id] 33 | WHERE a.[Id] IN ( @p0, @p1, @p2, @p3 );"; 34 | } 35 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbUnitObjectContentExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 对象内容表达式,当查询SELECT子句时只返回一个对象属性时,该对象表示需要内容的成员访问引用。 8 | /// 9 | public class DbUnitObjectContentExpression : DbUnitItemTypeExpression 10 | { 11 | /// 12 | /// 创建对象内容表达式。 13 | /// 14 | /// 对象成员引用表达式。 15 | public DbUnitObjectContentExpression(DbObjectMemberExpression member) 16 | : base(((System.Reflection.PropertyInfo)member.Member).PropertyType) 17 | { 18 | Content = member; 19 | } 20 | /// 21 | /// 内容表达式。 22 | /// 23 | public DbObjectMemberExpression Content { get; private set; } 24 | /// 25 | public override EExpressionType ExpressionType => EExpressionType.UnitObjectContent; 26 | } 27 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/DbQueryOperateBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | using System; 7 | using System.Linq.Expressions; 8 | /// 9 | /// 数据查询操作基类。 10 | /// 11 | internal abstract class DbQueryOperateBase : DbOperateBase 12 | { 13 | /// 14 | /// 初始化数据查询操作。 15 | /// 16 | /// 数据上下文。 17 | /// 查询表达式。 18 | /// 查询项CLR类型。 19 | internal DbQueryOperateBase(DbContext context, Expression expression, Type type) 20 | : base(context, type) 21 | { 22 | Expression = expression; 23 | } 24 | /// 25 | /// 查询表达式。 26 | /// 27 | public Expression Expression { get; } 28 | /// 29 | public override bool HasResult => true; 30 | } 31 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbGroupJoinExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 分组并连接表达式。 8 | /// 9 | public class DbGroupJoinExpression : DbInnerJoinExpression 10 | { 11 | /// 12 | /// 创建分组并连接表达式。 13 | /// 14 | /// 源表达式。 15 | /// 目标表达式。 16 | /// 左端键表达式。 17 | /// 右端键表达式。 18 | /// 当前连接后输出的新对象表达工。 19 | public DbGroupJoinExpression(DbUnitTypeExpression source, DbUnitTypeExpression target, DbExpression left, DbExpression right, DbUnitItemTypeExpression newExp) 20 | : base(source, target, left, right, newExp) 21 | { } 22 | /// 23 | public override EExpressionType ExpressionType => EExpressionType.GroupJoin; 24 | } 25 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbOrderExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 排序表达式。 8 | /// 9 | public class DbOrderExpression : DbExpression 10 | { 11 | /// 12 | /// 创建排序表达式。 13 | /// 14 | /// 排序成员表达式。 15 | /// 排序种类。 16 | public DbOrderExpression(DbExpression member, EOrderKind kind) 17 | { 18 | Member = member; 19 | Kind = kind; 20 | } 21 | /// 22 | /// 排序成员表达式。 23 | /// 24 | public DbExpression Member { get; private set; } 25 | /// 26 | /// 排序种类。 27 | /// 28 | public EOrderKind Kind { get; private set; } 29 | /// 30 | public override EExpressionType ExpressionType => EExpressionType.Order; 31 | } 32 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbUnitValueContentExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 单元值内容表达式,当查询SELECT子句时只返回一个基础数据类型的属性时 8 | /// ,该对象表示需要内容的成员访问引用。 9 | /// 10 | public class DbUnitValueContentExpression : DbUnitItemTypeExpression 11 | { 12 | /// 13 | /// 使用指定的引用成员,创建一个单元值内容表达式。 14 | /// 15 | /// 引用成员表达式。 16 | public DbUnitValueContentExpression(DbMemberExpression member) 17 | : base(((System.Reflection.PropertyInfo)member.Member).PropertyType) 18 | { 19 | Content = member; 20 | } 21 | /// 22 | /// 当前值表达式。 23 | /// 24 | public DbMemberExpression Content { get; private set; } 25 | /// 26 | public override EExpressionType ExpressionType => EExpressionType.UnitValueContent; 27 | } 28 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbConstantExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System; 7 | /// 8 | /// 常量表达式。 9 | /// 10 | public class DbConstantExpression : DbExpression 11 | { 12 | /// 13 | /// 创建常量表达式。 14 | /// 15 | /// 常量的CLR类型。 16 | /// 常量值。 17 | public DbConstantExpression(Type type, object value) 18 | { 19 | ClrType = type; 20 | Value = value; 21 | } 22 | /// 23 | /// 常量的CLR类型。 24 | /// 25 | public Type ClrType { get; private set; } 26 | /// 27 | /// 常量值。 28 | /// 29 | public object Value { get; private set; } 30 | /// 31 | public override EExpressionType ExpressionType => EExpressionType.Constant; 32 | } 33 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/GeneratedExpressionAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System.Linq.Expressions; 7 | using Caredev.Mego.Resolve.ValueGenerates; 8 | /// 9 | /// 表达式生成值特性,该特性标识当前属性在提交数据时按指定表达式生成值。 10 | /// 11 | public abstract class GeneratedExpressionAttribute : GeneratedValueBaseAttribute 12 | { 13 | /// 14 | /// 创建表达式生成值特性。 15 | /// 16 | /// 生成时的目的。 17 | public GeneratedExpressionAttribute(EGeneratedPurpose purpose) 18 | : base(purpose) 19 | { 20 | } 21 | /// 22 | /// 生成值使用的表达式。 23 | /// 24 | public virtual Expression Expression { get; protected set; } 25 | /// 26 | /// 生成选项。 27 | /// 28 | public override EGeneratedOption GeneratedOption => EGeneratedOption.Expression; 29 | } 30 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SqlServer/Query/Inherit/SingleEntityTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Inherit 2 | { 3 | public partial class SingleEntityTest 4 | { 5 | private const string QueryAllDataTestSql = 6 | @"SELECT a.[Id] , 7 | a.[Code] , 8 | a.[Name] , 9 | b.[Category] , 10 | b.[IsValid] , 11 | b.[UpdateDate] 12 | FROM [dbo].[ProductBases] AS a 13 | INNER JOIN [dbo].[Products] AS b ON a.[Id] = b.[Id];"; 14 | private const string OrderQueryDataTestSql = 15 | @"SELECT a.[Id] , 16 | a.[Code] , 17 | a.[Name] , 18 | b.[Category] , 19 | b.[IsValid] , 20 | b.[UpdateDate] 21 | FROM [dbo].[ProductBases] AS a 22 | INNER JOIN [dbo].[Products] AS b ON a.[Id] = b.[Id] 23 | ORDER BY b.[Category] ASC;"; 24 | private const string QueryFilterContainsTestSql = 25 | @"SELECT a.[Id] , 26 | a.[Code] , 27 | a.[Name] , 28 | b.[Category] , 29 | b.[IsValid] , 30 | b.[UpdateDate] 31 | FROM [dbo].[ProductBases] AS a 32 | INNER JOIN [dbo].[Products] AS b ON a.[Id] = b.[Id] 33 | WHERE a.[Id] IN ( @p0, @p1, @p2, @p3 );"; 34 | } 35 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbJoinKeyPairExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 数据单元连接操作的键匹配表达式。 8 | /// 9 | public class DbJoinKeyPairExpression : DbExpression 10 | { 11 | /// 12 | /// 创建连接表达式。 13 | /// 14 | /// 连接左端键的表达式。 15 | /// 连接右端键的表达式。 16 | public DbJoinKeyPairExpression(DbExpression left, DbExpression right) 17 | { 18 | Left = left; 19 | Right = right; 20 | } 21 | /// 22 | /// 连接左端键的表达式。 23 | /// 24 | public DbExpression Left { get; } 25 | /// 26 | /// 连接右端键的表达式 27 | /// 28 | public DbExpression Right { get; } 29 | /// 30 | public override EExpressionType ExpressionType => EExpressionType.JoinKeyPair; 31 | } 32 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Metadatas/MemberMetadata.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Metadatas 5 | { 6 | using System.Reflection; 7 | /// 8 | /// CLR成员元数据。 9 | /// 10 | public class MemberMetadata : IPropertyMetadata 11 | { 12 | /// 13 | /// 创建CLR成员元数据。 14 | /// 15 | /// 成员CLR描述对象。 16 | /// 成员种类。 17 | public MemberMetadata(PropertyInfo member, MemberKind kind) 18 | { 19 | Member = member; 20 | Kind = kind; 21 | } 22 | /// 23 | /// 成员种类。 24 | /// 25 | public MemberKind Kind { get; } 26 | /// 27 | /// 当前成员在类型元数据中的索引。 28 | /// 29 | public int Index { get; } 30 | /// 31 | /// 成员CLR描述对象。 32 | /// 33 | public PropertyInfo Member { get; } 34 | } 35 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/DbCreateTableOperate.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | /// 10 | /// 创建表操作。 11 | /// 12 | internal class DbCreateTableOperate : DbMaintenanceOperateBase 13 | { 14 | /// 15 | /// 初始化创建表操作。 16 | /// 17 | /// 数据上下文。 18 | /// 数据项CLR类型。 19 | /// 当前操作类型。 20 | /// 操作对象名称。 21 | internal DbCreateTableOperate(DbContext context, Type type, EOperateType operateType, DbName name) 22 | : base(context, type, name) 23 | { 24 | _Type = operateType; 25 | } 26 | /// 27 | public override EOperateType Type => _Type; 28 | private readonly EOperateType _Type; 29 | } 30 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/PostgreSQL/Query/Inherit/SingleEntityTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Query.Inherit 2 | { 3 | public partial class SingleEntityTest 4 | { 5 | private const string QueryAllDataTestSql = 6 | @"SELECT a.[Id] , 7 | a.[Code] , 8 | a.[Name] , 9 | b.[Category] , 10 | b.[IsValid] , 11 | b.[UpdateDate] 12 | FROM [dbo].[ProductBases] AS a 13 | INNER JOIN [dbo].[Products] AS b ON a.[Id] = b.[Id];"; 14 | private const string OrderQueryDataTestSql = 15 | @"SELECT a.[Id] , 16 | a.[Code] , 17 | a.[Name] , 18 | b.[Category] , 19 | b.[IsValid] , 20 | b.[UpdateDate] 21 | FROM [dbo].[ProductBases] AS a 22 | INNER JOIN [dbo].[Products] AS b ON a.[Id] = b.[Id] 23 | ORDER BY b.[Category] ASC;"; 24 | private const string QueryFilterContainsTestSql = 25 | @"SELECT a.[Id] , 26 | a.[Code] , 27 | a.[Name] , 28 | b.[Category] , 29 | b.[IsValid] , 30 | b.[UpdateDate] 31 | FROM [dbo].[ProductBases] AS a 32 | INNER JOIN [dbo].[Products] AS b ON a.[Id] = b.[Id] 33 | WHERE a.[Id] IN ( @p0, @p1, @p2, @p3 );"; 34 | } 35 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DbQuery`.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego 5 | { 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Linq.Expressions; 9 | /// 10 | /// 泛型数据查询对象。 11 | /// 12 | /// 13 | public sealed class DbQuery : DbQuery, IOrderedQueryable 14 | { 15 | /// 16 | /// 初始化实例对象。 17 | /// 18 | /// 19 | /// 20 | public DbQuery(DbContext context, Expression expression) 21 | : base(context, expression, typeof(T)) 22 | { 23 | } 24 | /// 25 | /// 接口实现。 26 | /// 27 | /// 28 | IEnumerator IEnumerable.GetEnumerator() 29 | { 30 | return Operate.Result.OfType().GetEnumerator(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/RelationActionAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using Caredev.Mego.Resolve; 7 | using System; 8 | /// 9 | /// 数据关系操作行为特性。 10 | /// 11 | [AttributeUsage(AttributeTargets.Property)] 12 | public class RelationActionAttribute : Attribute, IColumnAnnotation 13 | { 14 | /// 15 | /// 创建行为特性。 16 | /// 17 | /// 更新时行为。 18 | /// 删除时行为。 19 | public RelationActionAttribute(EReferenceAction? update, EReferenceAction? delete) 20 | { 21 | Update = update; 22 | Delete = delete; 23 | } 24 | /// 25 | /// 更新时行为。 26 | /// 27 | public EReferenceAction? Update { get; } 28 | /// 29 | /// 删除时行为。 30 | /// 31 | public EReferenceAction? Delete { get; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SqlServerCe/DbFeatureTest.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Caredev.Mego.Tests.Core 3 | { 4 | using System.Text; 5 | using System.Data.SqlServerCe; 6 | using System.IO; 7 | public partial class DbFeatureTest 8 | { 9 | public const int MaxInsertRowCount = 1000; 10 | public const int MaxParameterCount = 2098; 11 | 12 | public const bool HasMaxInsertRowCount = false; 13 | public const bool HasMaxParameterCount = false; 14 | 15 | public const string MaxParameterCountTestSql = @"SELECT * FROM [Customers] WHERE [Id] IN "; 16 | public const string ParameterPrefix = "@p"; 17 | 18 | public string MaxInsertRowCountTestSql(string name, int count) 19 | { 20 | return "SELECT 1"; 21 | } 22 | 23 | public void CreateDatabaseIfNoExsits(DbContext context) 24 | { 25 | var stringbuilder = new SqlCeConnectionStringBuilder(context.Database.Connection.ConnectionString); 26 | var database = stringbuilder.DataSource; 27 | if (!File.Exists(database)) 28 | { 29 | new SqlCeEngine(stringbuilder.ToString()).CreateDatabase(); 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/CommitExpressionMember.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators 5 | { 6 | using Caredev.Mego.Resolve.Expressions; 7 | using Caredev.Mego.Resolve.Metadatas; 8 | using Caredev.Mego.Resolve.ValueGenerates; 9 | /// 10 | /// 表达式提交成员。 11 | /// 12 | public class CommitExpressionMember : CommitMember 13 | { 14 | /// 15 | /// 创建提交成员。 16 | /// 17 | /// 列元数据。 18 | /// 值生成对象。 19 | /// 当前值的表达式。 20 | public CommitExpressionMember(ColumnMetadata metadata, ValueGenerateBase generator, DbExpression expression) 21 | : base(metadata, generator, ECommitValueType.Expression) 22 | { 23 | Expression = expression; 24 | } 25 | /// 26 | /// 值表达式。 27 | /// 28 | public DbExpression Expression { get; } 29 | } 30 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Exceptions/GeneratorNotFoundException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Exceptions 5 | { 6 | using System; 7 | /// 8 | /// 在查找 SQL 代码生成器时没有找到时会抛出该异常。 9 | /// 10 | [Serializable] 11 | public class GeneratorNotFoundException : Exception 12 | { 13 | /// 14 | /// 创建异常对象。 15 | /// 16 | public GeneratorNotFoundException() 17 | : base() 18 | { } 19 | /// 20 | /// 创建异常对象。 21 | /// 22 | /// 异常消息。 23 | public GeneratorNotFoundException(string message) 24 | : base(message) 25 | { } 26 | /// 27 | /// 创建异常对象。 28 | /// 29 | /// 异常消息。 30 | /// 内部异常。 31 | public GeneratorNotFoundException(string message, Exception innerException) 32 | : base(message, innerException) 33 | { } 34 | } 35 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Providers/SqlServerCeAccessProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Providers 5 | { 6 | using Caredev.Mego.Resolve.Commands; 7 | using Caredev.Mego.Resolve.Metadatas; 8 | using Caredev.Mego.Resolve.Operates; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Data.Common; 12 | using System.Reflection; 13 | /// 14 | /// 访问Nuget组件: Microsoft.SqlServer.Compact 15 | /// 16 | internal class SqlServerCeAccessProvider : DbAccessProvider 17 | { 18 | /// 19 | public override bool IsExclusive => true; 20 | /// 21 | public override string ProviderName => "System.Data.SqlServerCe"; 22 | /// 23 | public override EExecutionMode ExecutionMode => EExecutionMode.SingleStatement; 24 | /// 25 | public override ICustomCommand CreateCustomCommand() 26 | { 27 | return new MicrosoftCustomCommand(Factory); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/ValueConversion/BooleanToInt32Converter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.ValueConversion 5 | { 6 | using System; 7 | using System.Reflection; 8 | /// 9 | /// 从转换器。 10 | /// 11 | public class BooleanToInt32Converter 12 | { 13 | private readonly static object TrueValue = 1; 14 | private readonly static object FalseValue = 0; 15 | /// 16 | /// 向数据对象转换值。 17 | /// 18 | /// 转换值。 19 | /// 转换结果 20 | public static bool ConvertToObject(int value) 21 | { 22 | return value != 0; 23 | } 24 | /// 25 | /// 向存储转换值。 26 | /// 27 | /// 转换值。 28 | /// 转换结果 29 | public static object ConvertToStorage(bool value) 30 | { 31 | return value ? TrueValue : FalseValue; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbMemberExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System.Reflection; 7 | /// 8 | /// 成员访问表达式。 9 | /// 10 | public class DbMemberExpression : DbExpression, IDbMemberExpression 11 | { 12 | /// 13 | /// 创建成员访问表达式。 14 | /// 15 | /// 成员CLR描述对象。 16 | /// 源表达式。 17 | public DbMemberExpression(MemberInfo member, DbExpression source) 18 | { 19 | Member = member; 20 | Expression = source; 21 | } 22 | /// 23 | /// 成员CLR描述对象。 24 | /// 25 | public MemberInfo Member { get; private set; } 26 | /// 27 | /// 源表达式。 28 | /// 29 | public DbExpression Expression { get; private set; } 30 | /// 31 | public override EExpressionType ExpressionType => EExpressionType.MemberAccess; 32 | } 33 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/PostgreSQL/Commit/Simple/DeleteTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Commit.Simple 2 | { 3 | public partial class DeleteTest 4 | { 5 | private const string DeleteSingleTestSql = 6 | @"DELETE FROM ""public"".""OrderDetails"" AS a 7 | WHERE a.""Id"" = @p0 8 | AND a.""Discount"" = @p1;"; 9 | 10 | private const string DeleteMultiForKeyTestSql = 11 | @"DELETE FROM ""public"".""OrderDetails"" AS a 12 | WHERE a.""Id"" IN ( @p0, @p1, @p2 );"; 13 | 14 | private const string DeleteMultiForKeysTestSql = 15 | @"DELETE FROM ""public"".""Warehouses"" AS a 16 | USING ( VALUES 17 | (@p0,@p0,@p1), 18 | (@p0,@p2,@p3) 19 | ) AS b (""Id"",""Number"",""Address"") 20 | WHERE a.""Id"" = b.""Id"" AND a.""Number"" = b.""Number"" AND a.""Address"" = b.""Address"";"; 21 | 22 | private const string DeleteStatementForExpressionTestSql = 23 | @"DELETE FROM ""public"".""Warehouses"" AS a 24 | WHERE a.""Id"" > @p0;"; 25 | 26 | private const string DeleteStatementForQueryTestSql = 27 | @"DELETE FROM ""public"".""Warehouses"" AS a 28 | USING ""public"".""Customers"" AS b 29 | WHERE a.""Id"" > b.""Id"" AND a.""Number"" > @p0;"; 30 | } 31 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Common/InheritTypeComparer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Common 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | /// 9 | /// 类型继承关系比较器。 10 | /// 11 | internal class InheritTypeComparer : IComparer 12 | { 13 | /// 14 | /// 比较器当前实例。 15 | /// 16 | public static readonly InheritTypeComparer Instance = new InheritTypeComparer(); 17 | /// 18 | /// 单例模式,私有化比较器构造函数。 19 | /// 20 | private InheritTypeComparer() { } 21 | /// 22 | /// 比较两个类型的继承关系,如果类型x是类型y的父级则返回 -1,反之返回 1,相同则返回 0。 23 | /// 24 | /// 参与比较的类型。 25 | /// 参与比较的类型。 26 | /// 相同返回 0,如果 y 继承自 x 返回 1,否则返回 -1。 27 | public int Compare(Type x, Type y) 28 | { 29 | if (x.Equals(y)) 30 | return 0; 31 | return x.IsAssignableFrom(y) ? -1 : 1; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbSetFunctionExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System; 7 | using System.Reflection; 8 | /// 9 | /// 数据集函数表达式。 10 | /// 11 | public class DbSetFunctionExpression : DbMapFunctionExpression 12 | { 13 | /// 14 | /// 创建数据集函数表达式。 15 | /// 16 | /// 函数的CLR对象。 17 | /// 函数种类。 18 | /// 函数参数。 19 | public DbSetFunctionExpression(MethodInfo func, EMapFunctionKind kind, params DbExpression[] argus) 20 | : base(func, kind, argus) 21 | { 22 | ReturnClrType = func.ReturnType.GetGenericArguments()[0]; 23 | } 24 | /// 25 | /// 函数返回值的CLR类型。 26 | /// 27 | public Type ReturnClrType { get; private set; } 28 | /// 29 | public override EExpressionType ExpressionType => EExpressionType.SetFunction; 30 | } 31 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbCrossJoinExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System.Linq; 7 | /// 8 | /// 笛卡尔积连接表达式。 9 | /// 10 | public class DbCrossJoinExpression : DbSetOperationExpression 11 | { 12 | /// 13 | /// 创建笛卡尔积连接表达式。 14 | /// 15 | /// 源表达式。 16 | /// 目标表达式。 17 | /// 连接后输出的项表达式。 18 | public DbCrossJoinExpression(DbUnitTypeExpression source, DbUnitTypeExpression target, DbUnitItemTypeExpression newExp) 19 | : base(typeof(IQueryable<>).MakeGenericType(newExp.ClrType), source, newExp) 20 | { 21 | Target = target; 22 | } 23 | /// 24 | /// 目标单元表达式。 25 | /// 26 | public DbUnitTypeExpression Target { get; private set; } 27 | /// 28 | public override EExpressionType ExpressionType => EExpressionType.CrossJoin; 29 | } 30 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Exceptions/GenerateException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Exceptions 5 | { 6 | using Caredev.Mego.Resolve.Outputs; 7 | using System; 8 | using System.Linq.Expressions; 9 | /// 10 | /// 生成代码异常。 11 | /// 12 | [Serializable] 13 | public class GenerateException : Exception 14 | { 15 | /// 16 | /// 创建异常对象。 17 | /// 18 | public GenerateException() 19 | : base() 20 | { 21 | } 22 | /// 23 | /// 创建异常对象。 24 | /// 25 | /// 异常消息。 26 | public GenerateException(string message) 27 | : base(message) 28 | { 29 | } 30 | /// 31 | /// 创建异常对象。 32 | /// 33 | /// 异常消息。 34 | /// 内部异常。 35 | public GenerateException( string message, Exception innerException) 36 | : base(message, innerException) 37 | { 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/MySql/Commit/Simple/DeleteTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Commit.Simple 2 | { 3 | public partial class DeleteTest 4 | { 5 | private const string DeleteSingleTestSql = 6 | @"DELETE a 7 | FROM `orderdetails` AS a 8 | WHERE a.`Id` = @p0 9 | AND a.`Discount` = @p1;"; 10 | 11 | private const string DeleteMultiForKeyTestSql = 12 | @"DELETE a 13 | FROM `OrderDetails` AS a 14 | WHERE a.`Id` IN ( @p0, @p1, @p2 );"; 15 | 16 | private const string DeleteMultiForKeysTestSql = 17 | @"CREATE TEMPORARY TABLE `t$1` ( 18 | `Id` int NULL, 19 | `Number` int NULL, 20 | `Address` longtext NULL 21 | ); 22 | INSERT INTO `t$1` (`Id`, `Number`, `Address`) 23 | VALUES (@p0, @p0, @p1), 24 | (@p0, @p2, @p3); 25 | DELETE a 26 | FROM `warehouses` AS a 27 | INNER JOIN `t$1` AS b 28 | ON a.`Id` = b.`Id` 29 | AND a.`Number` = b.`Number` 30 | AND a.`Address` = b.`Address`;"; 31 | 32 | private const string DeleteStatementForExpressionTestSql = 33 | @"DELETE a 34 | FROM `Warehouses` AS a 35 | WHERE a.`Id` > @p0;"; 36 | 37 | private const string DeleteStatementForQueryTestSql = 38 | @"DELETE a 39 | FROM `Warehouses` AS a 40 | CROSS JOIN `Customers` AS b 41 | WHERE a.`Id` > b.`Id` 42 | AND a.`Number` > @p0;"; 43 | } 44 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbGroupItemExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 针对单元项表达的分组项表达式。 8 | /// 9 | public class DbGroupItemExpression : DbUnitItemTypeExpression, IDbUnitTypeExpression 10 | { 11 | /// 12 | /// 创建分组项表达式。 13 | /// 14 | /// 单元项表达式。 15 | public DbGroupItemExpression(DbUnitItemTypeExpression unititem) 16 | : base(unititem.ClrType) 17 | { 18 | Source = unititem; 19 | Item = new DbDataItemExpression(unititem.ClrType) 20 | { 21 | Unit = this 22 | }; 23 | } 24 | /// 25 | /// 源表达式。 26 | /// 27 | public DbUnitItemTypeExpression Source { get; private set; } 28 | /// 29 | /// 单元项表达式。 30 | /// 31 | public DbUnitItemTypeExpression Item { get; private set; } 32 | /// 33 | public override EExpressionType ExpressionType => EExpressionType.GroupItem; 34 | } 35 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbDataSetExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | /// 9 | /// 数据集对象表达式,对应于数据库表(包含临时表)或视图 10 | /// 11 | public class DbDataSetExpression : DbUnitTypeExpression, IDbExpandUnitExpression 12 | { 13 | /// 14 | /// 数据集对象表达式 15 | /// 16 | /// 数据对象类型。 17 | /// 数据集名称。 18 | public DbDataSetExpression(Type type, DbName name = null) 19 | : base(type, new DbDataItemExpression(type.GetGenericArguments()[0])) 20 | { 21 | Name = name; 22 | } 23 | /// 24 | /// 当前数据集展开的成员表达式集合。 25 | /// 26 | public IList ExpandItems { get; } = new List(); 27 | /// 28 | public override EExpressionType ExpressionType => EExpressionType.DataSet; 29 | /// 30 | /// 自定义名称。 31 | /// 32 | internal DbName Name { get; } 33 | } 34 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/CommitKeyUnit.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators 5 | { 6 | using Caredev.Mego.Resolve.Metadatas; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | /// 11 | /// 具有一个或多个主键的提交单元。 12 | /// 13 | public class CommitKeyUnit : CommitUnitBase 14 | { 15 | /// 16 | /// 创建提交单元。 17 | /// 18 | /// 表元数据。 19 | public CommitKeyUnit(TableMetadata table) 20 | : base(table) 21 | { 22 | } 23 | /// 24 | /// 主键成员集合。 25 | /// 26 | public IEnumerable Keys => _Keys; 27 | private List _Keys = new List(); 28 | /// 29 | public override void Add(CommitMember member) 30 | { 31 | if (member.Metadata.IsKey) 32 | { 33 | _Keys.Add(member); 34 | } 35 | else 36 | { 37 | base.Add(member); 38 | } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbUnitFunctionExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System.Collections.Generic; 7 | /// 8 | /// 单元函数表达式,它表示一个返回集合数据的函数表达式,例如数据库的表值函数对象。 9 | /// 10 | public class DbUnitFunctionExpression : DbUnitTypeExpression, IDbExpandUnitExpression 11 | { 12 | /// 13 | /// 创建单元函数表达式。 14 | /// 15 | /// 数据集函数。 16 | public DbUnitFunctionExpression(DbSetFunctionExpression function) 17 | : base(function.ClrType, new DbDataItemExpression(function.ReturnClrType)) 18 | { 19 | Function = function; 20 | } 21 | /// 22 | /// 数据集函数。 23 | /// 24 | public DbSetFunctionExpression Function { get; private set; } 25 | /// 26 | public override EExpressionType ExpressionType => EExpressionType.UnitFunction; 27 | /// 28 | /// 当前单元展开的表达式内容。 29 | /// 30 | public IList ExpandItems { get; } = new List(); 31 | } 32 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/GeneratedMemoryValueAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System; 7 | using Caredev.Mego.Resolve.ValueGenerates; 8 | /// 9 | /// 内存中生成值特性,通过指定类型的生成器生成值。 10 | /// 11 | [AttributeUsage(AttributeTargets.Property)] 12 | public sealed class GeneratedMemoryValueAttribute : GeneratedValueBaseAttribute 13 | { 14 | /// 15 | /// 创建内存中生成值特性。 16 | /// 17 | /// 生成器类型,该类型必须实现接口。 18 | /// 生成目的。 19 | public GeneratedMemoryValueAttribute(Type generatorType, EGeneratedPurpose purpose = EGeneratedPurpose.Insert) 20 | : base(purpose) 21 | { 22 | GeneratorType = generatorType; 23 | } 24 | /// 25 | /// 值生成器类型。 26 | /// 27 | public Type GeneratorType { get; } 28 | /// 29 | /// 生成选项。 30 | /// 31 | public override EGeneratedOption GeneratedOption => EGeneratedOption.Memory; 32 | } 33 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbGroupSetExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 分组集合的表达式。 8 | /// 9 | public class DbGroupSetExpression : DbUnitTypeExpression, IDbDefaultUnitType 10 | { 11 | /// 12 | /// 创建分组集合的表达式。 13 | /// 14 | /// 分组的单元表达式。 15 | public DbGroupSetExpression(DbUnitTypeExpression unit) 16 | : base(unit.ClrType, new DbGroupItemExpression(unit.Item)) 17 | { 18 | Source = unit; 19 | } 20 | /// 21 | /// 当前表达的所属GroupJoin对象。 22 | /// 23 | public DbGroupJoinExpression Parent { get; set; } 24 | /// 25 | /// 对于外连接时如果目标为空时以表达式做为值。 26 | /// 27 | public DbExpression Default { get; set; } 28 | /// 29 | /// 分组的源表达式。 30 | /// 31 | public DbUnitTypeExpression Source { get; } 32 | /// 33 | public override EExpressionType ExpressionType => EExpressionType.GroupSet; 34 | } 35 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Oracle/Commit/Simple/UpdatePropertysTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Commit.Simple 2 | { 3 | public partial class UpdatePropertysTest 4 | { 5 | private const string UpdateSingleObjectTestSql = 6 | @"UPDATE ""SIMPLE"".""Customers"" a 7 | SET ""Address1"" = :p0 || :p1 || :p2, 8 | ""Name"" = :p3 9 | WHERE a.""Id"" = :p4 AND a.""Zip"" = :p5 10 | RETURNING ""Address1"" INTO :p6"; 11 | 12 | private const string UpdateMultiObjectTestSql = 13 | @"UPDATE ""SIMPLE"".""Customers"" a 14 | SET ""Address1"" = :p0 || :p1 || :p2, 15 | ""Name"" = :p3 16 | WHERE a.""Id"" = :p4 AND a.""Zip"" = :p5 17 | RETURNING ""Address1"" INTO :p6"; 18 | 19 | private const string UpdateGenerateSingleObjectTestSql = 20 | @"UPDATE ""SIMPLE"".""Products"" a 21 | SET ""Category"" = :p0, 22 | ""Code"" = :p1 || :p2, 23 | ""Name"" = :p3, 24 | ""UpdateDate"" = SYSDATE 25 | WHERE a.""Id"" = :p4 26 | RETURNING ""Code"",""UpdateDate"" INTO :p5,:p6"; 27 | 28 | private const string UpdateGenerateMultiObjectTestSql = 29 | @"UPDATE ""SIMPLE"".""Products"" a 30 | SET ""Category"" = :p0, 31 | ""Code"" = :p1 || :p2, 32 | ""Name"" = :p3, 33 | ""UpdateDate"" = SYSDATE 34 | WHERE a.""Id"" = :p4 35 | RETURNING ""Code"",""UpdateDate"" INTO :p5,:p6"; 36 | } 37 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/IDbSqlGenerator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve 5 | { 6 | using Caredev.Mego.Resolve.Expressions; 7 | using Caredev.Mego.Resolve.Operates; 8 | using System; 9 | /// 10 | /// SQL 脚本生成器接口。 11 | /// 12 | public interface IDbSqlGenerator 13 | { 14 | /// 15 | /// 根据当前操作内容及表达式生成 SQL 脚本。 16 | /// 17 | /// 操作对象。 18 | /// 表达式对象。 19 | /// 20 | string Generate(DbOperateBase operate, DbExpression content); 21 | /// 22 | /// 数据访问提供者名称。 23 | /// 24 | string ProviderName { get; } 25 | /// 26 | /// 当前生成器适用的数据库版本,系统使用一个数字表示一个 27 | /// 完整的版本号,其中高位字节表示主版本号,低位字节表示次版本号,例如0x0506, 28 | /// 表示数据库版本号为5.6,版本号获取由相应的 29 | /// 实现。 30 | /// 31 | short Version { get; } 32 | /// 33 | /// 数据库特性(该特性为针对某类数据库的全局特性)。 34 | /// 35 | DbFeature Feature { get; } 36 | } 37 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Exceptions/DbCommitConcurrencyException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Exceptions 5 | { 6 | using System; 7 | /// 8 | /// 数据提交并发异常,当预期若干数据对象的提交操作,实际上未影响到 9 | /// 数据库中指定数量的行数时引发异常。此时表示所提交的若干对象中, 10 | /// 有数个对象已被并发更新导致当前数据的并发标记不再匹配。 11 | /// 12 | [Serializable] 13 | public class DbCommitConcurrencyException : Exception 14 | { 15 | /// 16 | /// 创建异常对象。 17 | /// 18 | public DbCommitConcurrencyException() 19 | : base() 20 | { 21 | } 22 | /// 23 | /// 创建异常对象。 24 | /// 25 | /// 异常消息。 26 | public DbCommitConcurrencyException(string message) 27 | : base(message) 28 | { 29 | } 30 | /// 31 | /// 创建异常对象。 32 | /// 33 | /// 异常消息。 34 | /// 内部异常。 35 | public DbCommitConcurrencyException(string message, Exception innerException) 36 | : base(message, innerException) 37 | { 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Oracle/Constants.cs: -------------------------------------------------------------------------------- 1 | using Caredev.Mego.Resolve.ValueConversion; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Caredev.Mego.Tests 9 | { 10 | internal partial class Constants 11 | { 12 | public const string TestCategoryRootName = "Oracle11"; 13 | 14 | public static Models.Simple.OrderManageEntities CreateSimpleContext(bool isinitial = false) 15 | { 16 | var db = new Models.Simple.OrderManageEntities(Constants.ConnectionNameSimple); 17 | if (!isinitial) 18 | { 19 | db.Configuration.DatabaseFeature.DefaultSchema = "SIMPLE"; 20 | db.Configuration.Metadata.Register(typeof(BooleanToInt32Converter)); 21 | db.Configuration.Metadata.Register(typeof(GuidToByteArrayConverter)); 22 | } 23 | return db; 24 | } 25 | 26 | public static Models.Inherit.OrderManageEntities CreateInheritContext(bool isinitial = false) 27 | { 28 | var db = new Models.Inherit.OrderManageEntities(Constants.ConnectionNameInherit); 29 | if (!isinitial) 30 | { 31 | db.Configuration.DatabaseFeature.DefaultSchema = "INHERIT"; 32 | } 33 | return db; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | /// 9 | /// 查询表达式基类。 10 | /// 11 | public abstract class DbExpression : IDbExpression 12 | { 13 | private Dictionary _Children; 14 | /// 15 | /// 数据表达式类型。 16 | /// 17 | public abstract EExpressionType ExpressionType { get; } 18 | /// 19 | /// 获取或设置当前表达式的子表达式。 20 | /// 21 | /// 查找键值。 22 | /// 创建子表达式。 23 | /// 查找或创建的表达式。 24 | public DbExpression GetOrSetChildren(object key, Func creator) 25 | { 26 | if (_Children == null) 27 | _Children = new Dictionary(); 28 | if (_Children.TryGetValue(key, out DbExpression value)) 29 | return value; 30 | value = creator(); 31 | _Children.Add(key, value); 32 | return value; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/IdentityAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System; 7 | using Caredev.Mego.Resolve.ValueGenerates; 8 | /// 9 | /// 标识列值生成特性。 10 | /// 11 | [AttributeUsage(AttributeTargets.Property)] 12 | public sealed class IdentityAttribute : GeneratedValueBaseAttribute, IColumnAnnotation 13 | { 14 | /// 15 | /// 创建标识列值生成特性。 16 | /// 17 | /// 标识种子。 18 | /// 标识增量。 19 | public IdentityAttribute(int seed = 1, int increment = 1) 20 | : base(EGeneratedPurpose.Insert) 21 | { 22 | Seed = seed; 23 | Increment = increment; 24 | } 25 | /// 26 | /// 标识种子。 27 | /// 28 | public int Seed { get; } 29 | /// 30 | /// 标识增量。 31 | /// 32 | public int Increment { get; } 33 | /// 34 | /// 生成选项。 35 | /// 36 | public override EGeneratedOption GeneratedOption => EGeneratedOption.Identity; 37 | } 38 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/Contents/UpdateContent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators.Contents 5 | { 6 | using Caredev.Mego.Resolve.Expressions; 7 | using Caredev.Mego.Resolve.Metadatas; 8 | using Caredev.Mego.Resolve.Operates; 9 | using Caredev.Mego.Resolve.ValueGenerates; 10 | /// 11 | /// 更新数据的内容对象。 12 | /// 13 | public class UpdateContent : ContentUnitBase 14 | { 15 | /// 16 | /// 创建内容对象。 17 | /// 18 | /// 生成上下文。 19 | /// 操作对象。 20 | internal UpdateContent(GenerateContext context, DbObjectsOperateBase operate) 21 | : base(context, operate) 22 | { 23 | } 24 | /// 25 | public override ValueGenerateBase GetValueGenerator(ColumnMetadata column) => column.GeneratedForUpdate; 26 | /// 27 | public override void Inititalze(DbExpression content = null) 28 | { 29 | base.Inititalze(content); 30 | Unit = this.CreateCommitUnit(new CommitKeyUnit(Table), Table.Members, content); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/CommitUnitBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators 5 | { 6 | using Caredev.Mego.Resolve.Metadatas; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | /// 11 | /// 提交单元对接基类。 12 | /// 13 | public class CommitUnitBase 14 | { 15 | /// 16 | /// 初始化提交单元。 17 | /// 18 | /// 提交相应的表元数据。 19 | public CommitUnitBase(TableMetadata table) 20 | { 21 | Table = table; 22 | } 23 | /// 24 | /// 关联的表对象。 25 | /// 26 | public TableMetadata Table { get; } 27 | /// 28 | /// 数据成员。 29 | /// 30 | public IEnumerable Members => _Members; 31 | private List _Members = new List(); 32 | /// 33 | /// 添加成员对象。 34 | /// 35 | /// 要添加的成员。 36 | public virtual void Add(CommitMember member) 37 | { 38 | _Members.Add(member); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/SqlGeneratorBase.Statement.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators 5 | { 6 | using Caredev.Mego.Resolve.Expressions; 7 | using Caredev.Mego.Resolve.Generators.Fragments; 8 | using Caredev.Mego.Resolve.Operates; 9 | using System; 10 | public partial class SqlGeneratorBase 11 | { 12 | /// 13 | /// 生成语句片段。 14 | /// 15 | /// 生成上下文。 16 | /// 插入表达式。 17 | /// 生成结果。 18 | protected virtual SqlFragment GenerateForStatement(GenerateContext context, DbExpression content) 19 | { 20 | var operate = context.Data.Operate; 21 | switch (operate.Type) 22 | { 23 | case EOperateType.InsertStatement: return GenerateForInsertStatement(context, content); 24 | case EOperateType.UpdateStatement: return GenerateForUpdateStatement(context, content); 25 | case EOperateType.DeleteStatement: return GenerateForDeleteStatement(context, content); 26 | } 27 | throw new NotImplementedException(); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbSetConnectExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | /// 7 | /// 数据单元连接操作表达式。 8 | /// 9 | public class DbSetConnectExpression : DbSetOperationExpression 10 | { 11 | /// 12 | /// 创建数据集连接操作。 13 | /// 14 | /// 源数据单元表达式。 15 | /// 目标数据单元表达式。 16 | /// 连接种类。 17 | public DbSetConnectExpression(DbUnitTypeExpression source, DbUnitTypeExpression target, EConnectKind kind) 18 | : base(source.ClrType, source, new DbDataItemExpression(source.Item.ClrType)) 19 | { 20 | Target = target; 21 | Kind = kind; 22 | } 23 | /// 24 | /// 目标数据单元表达式。 25 | /// 26 | public DbUnitTypeExpression Target { get; private set; } 27 | /// 28 | /// 连接操作种类。 29 | /// 30 | public EConnectKind Kind { get; private set; } 31 | /// 32 | public override EExpressionType ExpressionType => EExpressionType.SetConnect; 33 | } 34 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Expressions/DbUnaryExpression.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Expressions 5 | { 6 | using System; 7 | /// 8 | /// 一元运算表达式。 9 | /// 10 | public class DbUnaryExpression : DbExpression 11 | { 12 | /// 13 | /// 创建一个指定表达式的一元运算表达式。 14 | /// 15 | /// 一元运算种类。 16 | /// 原始表达式。 17 | /// 输出的CLR类型。 18 | public DbUnaryExpression(EUnaryKind kind, DbExpression expression, Type type) 19 | { 20 | Kind = kind; 21 | Expression = expression; 22 | Type = type; 23 | } 24 | /// 25 | /// 原始表达式。 26 | /// 27 | public DbExpression Expression { get; } 28 | /// 29 | /// 输出的CLR类型。 30 | /// 31 | public Type Type { get; } 32 | /// 33 | /// 一元运算种类。 34 | /// 35 | public EUnaryKind Kind { get; } 36 | /// 37 | public override EExpressionType ExpressionType => EExpressionType.Unary; 38 | } 39 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Core/FunctionTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core 2 | { 3 | using System; 4 | using System.Linq; 5 | using Caredev.Mego.DataAnnotations; 6 | using Caredev.Mego.Tests.Models.Simple; 7 | using Microsoft.VisualStudio.TestTools.UnitTesting; 8 | [TestClass, TestCategory(Constants.TestCategoryRootName + ".Database")] 9 | public partial class FunctionTest 10 | { 11 | [TestMethod] 12 | public void CustomFunctionTest() 13 | { 14 | using (var db = CreateSimpleContext()) 15 | { 16 | var query = from a in db.Customers 17 | select new 18 | { 19 | a.Id, 20 | a.Name, 21 | AbsId = CustomAbs(a.Id) 22 | }; 23 | Utility.CompareSql(db, query.Expression, CustomFunctionTestSql); 24 | var data = query.ToArray(); 25 | Assert.IsTrue(data.Any(a => a.Id > 0)); 26 | } 27 | } 28 | 29 | [DbFunction("ABS", IsSystemFunction = true)] 30 | public int CustomAbs(int value) 31 | { 32 | throw new NotImplementedException(); 33 | } 34 | 35 | internal OrderManageEntities CreateSimpleContext() => Constants.CreateSimpleContext(); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Caredev.Mego/DbFunctions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego 5 | { 6 | using System; 7 | using Res = Properties.Resources; 8 | /// 9 | /// 数据库函数映射。 10 | /// 11 | public static class DbFunctions 12 | { 13 | /// 14 | /// 对于支持 Identity 插入数据的数据,该函数用于最后插入记录的自增列的值。 15 | /// 16 | /// 17 | public static int GetIdentity() => throw new InvalidOperationException(Res.ExceptionDisableInvode); 18 | /// 19 | /// 获取序列的当前值。 20 | /// 21 | /// 序列名。 22 | /// 架构名。 23 | /// 当前值。 24 | public static int SequenceValue(string name, string schema) => throw new InvalidOperationException(Res.ExceptionDisableInvode); 25 | /// 26 | /// 获取序列的下一个值。 27 | /// 28 | /// 序列名。 29 | /// 架构名。 30 | /// 下一个值。 31 | public static int SequenceNext(string name, string schema) => throw new InvalidOperationException(Res.ExceptionDisableInvode); 32 | } 33 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/Contents/DeleteContent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators.Contents 5 | { 6 | using Caredev.Mego.Resolve.Metadatas; 7 | using Caredev.Mego.Resolve.Operates; 8 | using System.Linq; 9 | /// 10 | /// 更新数据的内容对象。 11 | /// 12 | public class DeleteContent : ContentBase 13 | { 14 | /// 15 | /// 创建内容对象。 16 | /// 17 | /// 生成上下文。 18 | /// 操作对象。 19 | internal DeleteContent(GenerateContext context, DbObjectsOperateBase operate) 20 | : base(context, operate) 21 | { 22 | } 23 | /// 24 | protected override IPropertyValueLoader CreateLoader(GenerateContext context, TableMetadata table) 25 | { 26 | if (this.NeedConcurrencyCheck) 27 | { 28 | return new PropertyValueLoader(context, table, table.Keys.Concat(ConcurrencyMembers).ToArray()); 29 | } 30 | else 31 | { 32 | return new PropertyValueLoader(context, table, table.Keys); 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/DbRenameObjectOperate.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | /// 10 | /// 重命名对象操作。 11 | /// 12 | internal class DbRenameObjectOperate : DbMaintenanceOperateBase 13 | { 14 | /// 15 | /// 创建操作。 16 | /// 17 | /// 数据上下文。 18 | /// 相关CLR类型。 19 | /// 当前操作类型。 20 | /// 操作对象名称。 21 | /// 新名称。 22 | internal DbRenameObjectOperate(DbContext context, Type type, EOperateType operateType, DbName name, string newName) 23 | : base(context, type ?? typeof(object), name) 24 | { 25 | _Type = operateType; 26 | NewName = newName; 27 | } 28 | /// 29 | /// 新名称。 30 | /// 31 | public string NewName { get; } 32 | /// 33 | public override EOperateType Type => _Type; 34 | private readonly EOperateType _Type; 35 | } 36 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Access/Commit/Simple/UpdatePropertysTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Commit.Simple 2 | { 3 | public partial class UpdatePropertysTest 4 | { 5 | private const string UpdateSingleObjectTestSql = 6 | @"UPDATE [Customers] 7 | SET [Address1] = @p0 + @p1 + @p2 , 8 | [Name] = @p3 9 | WHERE [Id] = @p4; 10 | SELECT a.[Address1] 11 | FROM [Customers] AS a 12 | WHERE a.[Id] = @p4;"; 13 | 14 | private const string UpdateMultiObjectTestSql = 15 | @"UPDATE [Customers] 16 | SET [Address1] = @p0 + @p1 + @p2 , 17 | [Name] = @p3 18 | WHERE [Id] = @p4; 19 | SELECT a.[Address1] 20 | FROM [Customers] AS a 21 | WHERE a.[Id] = @p4;"; 22 | 23 | private const string UpdateGenerateSingleObjectTestSql = 24 | @"UPDATE [Products] 25 | SET [Category] = @p0 , 26 | [Code] = @p1 + @p2 , 27 | [Name] = @p1 , 28 | [UpdateDate] = NOW() 29 | WHERE [Id] = @p3; 30 | SELECT a.[Code] , 31 | a.[UpdateDate] 32 | FROM [Products] AS a 33 | WHERE a.[Id] = @p3;"; 34 | 35 | private const string UpdateGenerateMultiObjectTestSql = 36 | @"UPDATE [Products] 37 | SET [Category] = @p0 , 38 | [Code] = @p1 + @p2 , 39 | [Name] = @p1 , 40 | [UpdateDate] = NOW() 41 | WHERE [Id] = @p3; 42 | SELECT a.[Code] , 43 | a.[UpdateDate] 44 | FROM [Products] AS a 45 | WHERE a.[Id] = @p3;"; 46 | } 47 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/Excel/Commit/Simple/UpdatePropertysTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Commit.Simple 2 | { 3 | public partial class UpdatePropertysTest 4 | { 5 | private const string UpdateSingleObjectTestSql = 6 | @"UPDATE [Customers] 7 | SET [Address1] = @p0 + @p1 + @p2 , 8 | [Name] = @p3 9 | WHERE [Id] = @p4; 10 | SELECT a.[Address1] 11 | FROM [Customers] AS a 12 | WHERE a.[Id] = @p4;"; 13 | 14 | private const string UpdateMultiObjectTestSql = 15 | @"UPDATE [Customers] 16 | SET [Address1] = @p0 + @p1 + @p2 , 17 | [Name] = @p3 18 | WHERE [Id] = @p4; 19 | SELECT a.[Address1] 20 | FROM [Customers] AS a 21 | WHERE a.[Id] = @p4;"; 22 | 23 | private const string UpdateGenerateSingleObjectTestSql = 24 | @"UPDATE [Products] 25 | SET [Category] = @p0 , 26 | [Code] = @p1 + @p2 , 27 | [Name] = @p1 , 28 | [UpdateDate] = NOW() 29 | WHERE [Id] = @p3; 30 | SELECT a.[Code] , 31 | a.[UpdateDate] 32 | FROM [Products] AS a 33 | WHERE a.[Id] = @p3;"; 34 | 35 | private const string UpdateGenerateMultiObjectTestSql = 36 | @"UPDATE [Products] 37 | SET [Category] = @p0 , 38 | [Code] = @p1 + @p2 , 39 | [Name] = @p1 , 40 | [UpdateDate] = NOW() 41 | WHERE [Id] = @p3; 42 | SELECT a.[Code] , 43 | a.[UpdateDate] 44 | FROM [Products] AS a 45 | WHERE a.[Id] = @p3;"; 46 | } 47 | } -------------------------------------------------------------------------------- /test/Caredev.Mego.Tests/SqlServerCe/Commit/Simple/UpdatePropertysTest.cs: -------------------------------------------------------------------------------- 1 | namespace Caredev.Mego.Tests.Core.Commit.Simple 2 | { 3 | public partial class UpdatePropertysTest 4 | { 5 | private const string UpdateSingleObjectTestSql = 6 | @"UPDATE [Customers] 7 | SET [Address1] = @p0 + @p1 + @p2 , 8 | [Name] = @p3 9 | WHERE [Id] = @p4; 10 | SELECT a.[Address1] 11 | FROM [Customers] AS a 12 | WHERE a.[Id] = @p4;"; 13 | 14 | private const string UpdateMultiObjectTestSql = 15 | @"UPDATE [Customers] 16 | SET [Address1] = @p0 + @p1 + @p2 , 17 | [Name] = @p3 18 | WHERE [Id] = @p4; 19 | SELECT a.[Address1] 20 | FROM [Customers] AS a 21 | WHERE a.[Id] = @p4;"; 22 | 23 | private const string UpdateGenerateSingleObjectTestSql = 24 | @"UPDATE [Products] 25 | SET [Category] = @p0 , 26 | [Code] = @p1 + @p2 , 27 | [Name] = @p1 , 28 | [UpdateDate] = GETDATE() 29 | WHERE [Id] = @p3; 30 | SELECT a.[Code] , 31 | a.[UpdateDate] 32 | FROM [Products] AS a 33 | WHERE a.[Id] = @p3;"; 34 | 35 | private const string UpdateGenerateMultiObjectTestSql = 36 | @"UPDATE [Products] 37 | SET [Category] = @p0 , 38 | [Code] = @p1 + @p2 , 39 | [Name] = @p1 , 40 | [UpdateDate] = GETDATE() 41 | WHERE [Id] = @p3; 42 | SELECT a.[Code] , 43 | a.[UpdateDate] 44 | FROM [Products] AS a 45 | WHERE a.[Id] = @p3;"; 46 | } 47 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/DbMaintenanceOperateBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | using System; 7 | using System.Data.Common; 8 | /// 9 | /// 数据库维护操作基类。 10 | /// 11 | public abstract class DbMaintenanceOperateBase : DbOperateBase 12 | { 13 | /// 14 | /// 创建数据库维护操作。 15 | /// 16 | /// 数据库上下文。 17 | /// 相关的CLR类型。 18 | /// 当前操作对象名称。 19 | internal DbMaintenanceOperateBase(DbContext context, Type type, DbName name) 20 | : base(context, type) 21 | { 22 | Name = name; 23 | } 24 | /// 25 | /// 当前操作对象名称。 26 | /// 27 | public DbName Name { get; } 28 | /// 29 | public override bool HasResult => false; 30 | /// 31 | internal override bool Read(DbDataReader reader) => true; 32 | /// 33 | internal override string GenerateSql() 34 | { 35 | var context = Executor.Context; 36 | return context.Database.Generator.Generate(this, null); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/DbStatementOperateBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | using System; 7 | using System.Data.Common; 8 | using System.Linq.Expressions; 9 | /// 10 | /// 语句数据操作基类。 11 | /// 12 | public abstract class DbStatementOperateBase : DbOperateBase 13 | { 14 | /// 15 | /// 根据表达式创建语句操作。 16 | /// 17 | /// 操作目标。 18 | /// 语句操作表达式。 19 | /// 操作数据的CLR类型。 20 | internal DbStatementOperateBase(IDbSet target, Expression expression, Type type) 21 | : base(target.Context, type) 22 | { 23 | DbSet = target; 24 | Expression = expression; 25 | } 26 | /// 27 | /// 目标数据集。 28 | /// 29 | public IDbSet DbSet { get; } 30 | /// 31 | /// 操作相关的LINQ表达式。 32 | /// 33 | public Expression Expression { get; } 34 | /// 35 | public override bool HasResult => false; 36 | /// 37 | internal override bool Read(DbDataReader reader) => true; 38 | } 39 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/Contents/IContentUnit.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators.Contents 5 | { 6 | using Caredev.Mego.Resolve.Metadatas; 7 | using Caredev.Mego.Resolve.ValueGenerates; 8 | using System.Collections.Generic; 9 | /// 10 | /// 提交内容单元接口 11 | /// 12 | public interface IContentUnit 13 | { 14 | /// 15 | /// 生成上下文。 16 | /// 17 | GenerateContext GenerateContext { get; } 18 | /// 19 | /// 需要返回结果的成员。 20 | /// 21 | IEnumerable ReturnMembers { get; } 22 | /// 23 | /// 所有列元数据。 24 | /// 25 | IEnumerable Columns { get; } 26 | /// 27 | /// 注册需要返回的成员。 28 | /// 29 | /// 指定提交成员。 30 | /// 返回传入成员。 31 | CommitMember ReisterReturnMember(CommitMember member); 32 | /// 33 | /// 获取指定列的值生成对象。 34 | /// 35 | /// 指定数据列元数据。 36 | /// 值生成对象。 37 | ValueGenerateBase GetValueGenerator(ColumnMetadata column); 38 | } 39 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/ColumnAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System; 7 | /// 8 | /// 数据库列特性。 9 | /// 10 | [AttributeUsage(AttributeTargets.Property)] 11 | public class ColumnAttribute : Attribute, IColumnAnnotation 12 | { 13 | /// 14 | /// 创建数据库列特性。 15 | /// 16 | /// 列名。 17 | /// 数据库类型名。 18 | public ColumnAttribute(string name, string typename = null) 19 | { 20 | if (string.IsNullOrEmpty(name) 21 | #if !NET35 22 | || string.IsNullOrWhiteSpace(name) 23 | #endif 24 | ) 25 | { 26 | throw new ArgumentNullException(nameof(name)); 27 | } 28 | Name = name; 29 | TypeName = typename; 30 | } 31 | /// 32 | /// 列名。 33 | /// 34 | public string Name { get; internal set; } 35 | /// 36 | /// 列的顺序。 37 | /// 38 | public int Order { get; set; } 39 | /// 40 | /// 类型名。 41 | /// 42 | public string TypeName { get; } 43 | } 44 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/ValueGenerates/ValueGenerateMemory.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.ValueGenerates 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | /// 9 | /// 内存中值生成定义对象。 10 | /// 11 | internal sealed class ValueGenerateMemory : ValueGenerateBase 12 | { 13 | private readonly static Dictionary _Generators 14 | = new Dictionary(); 15 | /// 16 | /// 创建内存中值生成定义对象。 17 | /// 18 | /// 值生成器类型。 19 | public ValueGenerateMemory(Type type) 20 | : base() 21 | { 22 | if (!_Generators.TryGetValue(type, out IMemoryValueGenerator generator)) 23 | { 24 | generator = Activator.CreateInstance(type) as IMemoryValueGenerator; 25 | _Generators.Add(type, generator); 26 | } 27 | Generator = generator; 28 | } 29 | /// 30 | /// 值生成器实例。 31 | /// 32 | public IMemoryValueGenerator Generator { get; } 33 | /// 34 | public override EGeneratedOption GeneratedOption => EGeneratedOption.Memory; 35 | } 36 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/Contents/InheritDeleteContent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators.Contents 5 | { 6 | using System; 7 | using System.Linq; 8 | using Caredev.Mego.Resolve.Metadatas; 9 | using Caredev.Mego.Resolve.Operates; 10 | /// 11 | /// 更新继承数据的内容对象。 12 | /// 13 | public class InheritDeleteContent : InheritContentBase 14 | { 15 | /// 16 | /// 创建内容对象。 17 | /// 18 | /// 生成上下文。 19 | /// 操作对象。 20 | internal InheritDeleteContent(GenerateContext context, DbObjectsOperateBase operate) 21 | : base(context, operate) 22 | { 23 | Array.Reverse(Tables); 24 | } 25 | /// 26 | protected override IPropertyValueLoader CreateLoader(GenerateContext context, TableMetadata table) 27 | { 28 | if (this.NeedConcurrencyCheck) 29 | { 30 | return new PropertyValueLoader(context, table, table.Keys.Concat(ConcurrencyMembers).ToArray()); 31 | } 32 | else 33 | { 34 | return new PropertyValueLoader(context, table, table.Keys); 35 | } 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/DbPropertysOperateBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | using Caredev.Mego.Common; 7 | using System; 8 | using System.Collections; 9 | using System.Linq; 10 | using System.Linq.Expressions; 11 | /// 12 | /// 指定属性的操作基类。 13 | /// 14 | public abstract class DbPropertysOperateBase : DbObjectsOperateBase 15 | { 16 | /// 17 | /// 创建指定属性的操作。 18 | /// 19 | /// 操作目标。 20 | /// 操作表达式。 21 | /// 提交数据集合。 22 | /// 数据项类型。 23 | public DbPropertysOperateBase(IDbSet target, Expression expression, IEnumerable items, Type type) 24 | : base(target, items, type, CreateExpression((IQueryable)target, type, expression)) 25 | { 26 | } 27 | private static Expression CreateExpression(IQueryable source, Type type, Expression expression) 28 | { 29 | return System.Linq.Expressions.Expression.Call( 30 | SupportMembers.Queryable.Select.MakeGenericMethod(type, type), 31 | Expression.Constant(source), 32 | expression); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Metadatas/CompositeNavigateMetadata.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Metadatas 5 | { 6 | /// 7 | /// 复合关系元数据。 8 | /// 9 | public class CompositeNavigateMetadata : NavigateMetadata 10 | { 11 | /// 12 | /// 创建复合关系元数据。 13 | /// 14 | /// 关系源。 15 | /// 关系目标。 16 | /// 所在的表元数据。 17 | /// 关系主外键对。 18 | /// 复合关系主外键对。 19 | public CompositeNavigateMetadata( 20 | TableMetadata source, TableMetadata target, TableMetadata table, 21 | ForeignPrincipalPair[] pairs, ForeignPrincipalPair[] cpairs) 22 | : base(source, target, pairs) 23 | { 24 | RelationTable = table; 25 | CompositePairs = cpairs; 26 | } 27 | /// 28 | public override bool IsComposite => true; 29 | /// 30 | /// 复合关系中间表。 31 | /// 32 | public TableMetadata RelationTable { get; } 33 | /// 34 | /// 复合关系主外键对。 35 | /// 36 | public ForeignPrincipalPair[] CompositePairs { get; } 37 | } 38 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/DbRelationItem.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | /// 7 | /// 关系操作的数据项。 8 | /// 9 | public sealed class DbRelationItem 10 | { 11 | /// 12 | /// 创建关系操作的数据项。 13 | /// 14 | /// 源对象。 15 | /// 目标对象。 16 | public DbRelationItem(object source, object target) 17 | { 18 | Source = source; 19 | Target = target; 20 | } 21 | /// 22 | /// 源对象。 23 | /// 24 | public object Source { get; } 25 | /// 26 | /// 目标对象。 27 | /// 28 | public object Target { get; } 29 | /// 30 | public override bool Equals(object obj) 31 | { 32 | if (obj != null && obj is DbRelationItem) 33 | { 34 | var value = (DbRelationItem)obj; 35 | return value.Source == Source && value.Target == Target; 36 | } 37 | return false; 38 | } 39 | /// 40 | public override int GetHashCode() 41 | { 42 | return Source.GetHashCode() ^ Target.GetHashCode(); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/InversePropertyAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System; 7 | using System.Linq; 8 | using Res = Properties.Resources; 9 | /// 10 | /// 表示关系中用作外键的属性,属性所在的类为当前关系的主体,标识属性所指 11 | /// 向的类为当前关系的外键,这与相反。 12 | /// 13 | [AttributeUsage(AttributeTargets.Property)] 14 | public class InversePropertyAttribute : Attribute 15 | { 16 | /// 17 | /// 创建反转外键属性特性。 18 | /// 19 | /// 外键名称,多个名称以逗号分割。 20 | /// 主键名称,多个名称以逗号分割。 21 | public InversePropertyAttribute(string names, string principals = "") 22 | { 23 | Names = names.Split(',').Select(a => a.Trim()).ToArray(); 24 | Principals = principals.Split(',').Select(a => a.Trim()).ToArray(); 25 | if (Names.Length != Principals.Length) 26 | { 27 | throw new ArgumentException(Res.ExceptionKeyCountIsNotMatch); 28 | } 29 | } 30 | /// 31 | /// 外键属性名称集合。 32 | /// 33 | public string[] Names { get; } 34 | /// 35 | /// 关系主体的唯一键属性名。 36 | /// 37 | public string[] Principals { get; } 38 | } 39 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/Contents/InsertContent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators.Contents 5 | { 6 | using Caredev.Mego.Resolve.Expressions; 7 | using Caredev.Mego.Resolve.Metadatas; 8 | using Caredev.Mego.Resolve.Operates; 9 | using Caredev.Mego.Resolve.ValueGenerates; 10 | /// 11 | /// 插入数据的内容对象。 12 | /// 13 | public class InsertContent : ContentUnitBase 14 | { 15 | /// 16 | /// 创建内容对象。 17 | /// 18 | /// 生成上下文。 19 | /// 操作对象。 20 | internal InsertContent(GenerateContext context, DbObjectsOperateBase operate) 21 | : base(context, operate) 22 | { 23 | } 24 | /// 25 | /// 是否存在由表达式生成的主键成员。 26 | /// 27 | public bool HasExpressionKey => _HasExpressionKey; 28 | private bool _HasExpressionKey; 29 | /// 30 | public override ValueGenerateBase GetValueGenerator(ColumnMetadata column) => column.GeneratedForInsert; 31 | /// 32 | public override void Inititalze(DbExpression content = null) 33 | { 34 | base.Inititalze(content); 35 | Unit = this.CreateUnitForIdentity(Table, content, out _HasExpressionKey); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/EDatabaseObject.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | /// 7 | /// 数据库对象枚举。 8 | /// 9 | public enum EDatabaseObject 10 | { 11 | /// 12 | /// 数据库。 13 | /// 14 | Database, 15 | /// 16 | /// 表。 17 | /// 18 | Table, 19 | /// 20 | /// 视图。 21 | /// 22 | View, 23 | /// 24 | /// 序列。 25 | /// 26 | Sequence, 27 | /// 28 | /// 检查约束。 29 | /// 30 | CheckConstraint, 31 | /// 32 | /// 外键约束。 33 | /// 34 | ForeignKey, 35 | /// 36 | /// 主键约束。 37 | /// 38 | PrimaryKey, 39 | /// 40 | /// 默认值约束。 41 | /// 42 | DefaultConstraint, 43 | /// 44 | /// 标量函数。 45 | /// 46 | ScalarFunction, 47 | /// 48 | /// 表值函数。 49 | /// 50 | TableValuedFunction, 51 | /// 52 | /// 存储过程。 53 | /// 54 | StoredProcedure, 55 | /// 56 | /// 索引。 57 | /// 58 | Index 59 | } 60 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/DataAnnotations/DbFunctionAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.DataAnnotations 5 | { 6 | using System; 7 | using Res = Properties.Resources; 8 | /// 9 | /// 自定义数据库函数映射特性,该特性用于映射CLR中定义的静态函数 10 | /// 及实例函数到数据库函数,自定义函数优先级会低于系统函数。 11 | /// 12 | [AttributeUsage(AttributeTargets.Method)] 13 | public sealed class DbFunctionAttribute : Attribute 14 | { 15 | /// 16 | /// 创建自定义函数映射特性 17 | /// 18 | /// 19 | /// 20 | public DbFunctionAttribute(string name, string schema = "") 21 | { 22 | if (string.IsNullOrEmpty(name) 23 | #if !NET35 24 | || string.IsNullOrWhiteSpace(name) 25 | #endif 26 | ) 27 | { 28 | throw new ArgumentNullException(Res.ExceptionFunctionNameCannotEmpty, nameof(name)); 29 | } 30 | Name = name; 31 | } 32 | /// 33 | /// 映射函数名。 34 | /// 35 | public string Name { get; } 36 | /// 37 | /// 映射函数架构名。 38 | /// 39 | public string Schema { get; set; } 40 | /// 41 | /// 是否为系统函数,如果为是则会直接输出字符。 42 | /// 43 | public bool IsSystemFunction { get; set; } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Operates/DbQueryObjectOperate.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Operates 5 | { 6 | using Caredev.Mego.Resolve.Outputs; 7 | using System; 8 | using System.Data.Common; 9 | using System.Linq.Expressions; 10 | /// 11 | /// 查询单个对象操作。 12 | /// 13 | internal class DbQueryObjectOperate : DbQueryOperateBase 14 | { 15 | /// 16 | /// 创建查询单个对象操作。 17 | /// 18 | /// 数据上下文。 19 | /// 查询表达式。 20 | /// 数据项CLR类型。 21 | public DbQueryObjectOperate(DbContext context, Expression expression, Type itemType) 22 | : base(context, expression, itemType) 23 | { 24 | ItemType = itemType; 25 | } 26 | /// 27 | /// 数据项CLR类型。 28 | /// 29 | public Type ItemType { get; } 30 | /// 31 | /// 返回结果。 32 | /// 33 | public object Result { get; private set; } 34 | /// 35 | public override EOperateType Type => EOperateType.QueryObject; 36 | /// 37 | internal override bool Read(DbDataReader reader) 38 | { 39 | Result = ((ISingleOutput)Output).GetResult(reader); 40 | return true; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/Caredev.Mego/Resolve/Generators/Implement/ExcelGenerator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) CarefreeXT and Caredev Studios. All rights reserved. 2 | // Licensed under the GNU Lesser General Public License v3.0. 3 | // See License.txt in the project root for license information. 4 | namespace Caredev.Mego.Resolve.Generators.Implement 5 | { 6 | /// 7 | /// 针对 Excel 数据库的代码生成器。 8 | /// 9 | public abstract class ExcelBaseGenerator : MSLocalDbGenerator 10 | { 11 | /// 12 | public override FragmentWriterBase FragmentWriter 13 | { 14 | get 15 | { 16 | if (_FragmentWriter == null) 17 | { 18 | _FragmentWriter = new ExcelFragmentWriter(this); 19 | } 20 | return _FragmentWriter; 21 | } 22 | } 23 | private FragmentWriterBase _FragmentWriter; 24 | /// 25 | public override string ProviderName => "System.Data.OleDb.Excel"; 26 | /// 27 | public override DbFeature Feature => _Feature; 28 | private readonly DbFeature _Feature = new DbFeature() 29 | { 30 | Capability = EDbCapable.DataDefinition | 31 | EDbCapable.WindowFunction | EDbCapable.TableValuedFunction | 32 | EDbCapable.SubQuery 33 | }; 34 | } 35 | /// 36 | /// 针对 Access 数据库的代码生成器。 37 | /// 38 | public class ExcelGenerator : ExcelBaseGenerator 39 | { 40 | /// 41 | public override short Version => 0x0400; 42 | } 43 | } 44 | --------------------------------------------------------------------------------