当前位置: 首页>>代码示例>>C#>>正文


C# IClassMap.GetIdentityPropertyMaps方法代码示例

本文整理汇总了C#中IClassMap.GetIdentityPropertyMaps方法的典型用法代码示例。如果您正苦于以下问题:C# IClassMap.GetIdentityPropertyMaps方法的具体用法?C# IClassMap.GetIdentityPropertyMaps怎么用?C# IClassMap.GetIdentityPropertyMaps使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IClassMap的用法示例。


在下文中一共展示了IClassMap.GetIdentityPropertyMaps方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InstantiateObject

        private object InstantiateObject(Type type, IClassMap classMap, XmlNode xmlObject)
        {
            IObjectManager om = this.Context.ObjectManager;
            string element = classMap.GetDocElement();

            string identity = "";
            string separator = classMap.GetIdentitySeparator();

            foreach (IPropertyMap idPropertyMap in classMap.GetIdentityPropertyMaps())
            {
                if (identity.Length > 0)
                    identity += separator;

                if (idPropertyMap.DocElement.Length > 0)
                {
                    XmlNode idNode = xmlObject.SelectSingleNode(idPropertyMap.GetDocElement());
                    if (idNode != null)
                        identity += idNode.InnerText;
                    else
                        throw new NPersistException(String.Format("Could not find id element {0} for property {1} of class {2} in element {3}", idPropertyMap.GetDocElement(), idPropertyMap.Name, type.ToString(), xmlObject.Name));
                }
                else
                {
                    string attribName = idPropertyMap.GetDocAttribute();
                    if (xmlObject.Attributes[attribName] != null)
                        identity += xmlObject.Attributes[attribName].Value;
                    else
                        throw new NPersistException(String.Format("Could not find id attribute {0} for property {1} of class {2} in element {3}", attribName, idPropertyMap.Name, type.ToString(), xmlObject.Name));
                }
            }

            return this.Context.GetObjectById(identity, type, true);
        }
开发者ID:BackupTheBerlios,项目名称:puzzle-svn,代码行数:33,代码来源:DocumentPersistenceEngine.cs

示例2: FindNodeForObject

        protected virtual XmlNode FindNodeForObject(XmlNode xmlRoot, object obj, IClassMap classMap)
        {
            IObjectManager om = this.Context.ObjectManager;
            string element = classMap.GetDocElement();

            string xpath = "";

            foreach (IPropertyMap idPropertyMap in classMap.GetIdentityPropertyMaps() )
            {
                if (xpath.Length > 0 )
                    xpath += " and "; // do not localize

                if (idPropertyMap.DocElement.Length > 0)
                    xpath += idPropertyMap.GetDocElement() + " = \"" + om.GetPropertyValue(obj, idPropertyMap.Name).ToString() + "\""; // do not localize
                else
                    xpath += "@" + idPropertyMap.GetDocAttribute() + " = \"" + om.GetPropertyValue(obj, idPropertyMap.Name).ToString() + "\""; // do not localize
            }

            xpath = element + "[" + xpath + "]";

            return xmlRoot.SelectSingleNode(xpath);
        }
开发者ID:BackupTheBerlios,项目名称:puzzle-svn,代码行数:22,代码来源:DocumentPersistenceEngine.cs

示例3: AddTypeColumnToWhereClause

		private void AddTypeColumnToWhereClause(IClassMap classMap, SqlSearchCondition search) 
		{
			IColumnMap typeColumnMap = classMap.GetTypeColumnMap(); 
			if (typeColumnMap != null)
			{
				ITableMap tableMap = classMap.MustGetTableMap();
				SqlTableAlias tbl = null ;
				foreach (IPropertyMap idPropertyMap in classMap.GetIdentityPropertyMaps())
				{
					tbl = GetTableAlias(tableMap, idPropertyMap)  ;
					break;
				}

				SqlColumnAlias column = this.propertyPathTraverser.GetPropertyColumnAlias(tbl, ".NPersistTypeColumn" , typeColumnMap, ".NPersistTypeColumn");

				search.GetSqlComparePredicate(column, SqlCompareOperatorType.Equals, new SqlStringLiteral(classMap.TypeValue));				
				search.OrNext = true;
			}
		}
开发者ID:Dawn-of-Light,项目名称:Puzzle.NET,代码行数:19,代码来源:SqlEmitter.cs

示例4: GenerateRepositoryUpdateObjectMethod

        public static void GenerateRepositoryUpdateObjectMethod(IClassMap classMap, CodeTypeDeclaration classDecl)
        {
            IList propertyMaps = classMap.GetAllPropertyMaps();
            IList idPropertyMaps = classMap.GetIdentityPropertyMaps();

            CodeMemberMethod methodMember = new CodeMemberMethod() ;
            methodMember.Name = GetRepositoryUpdateObjectMethodName(classMap);

            CodeTypeReference typeReference = new CodeTypeReference(classMap.GetName());
            methodMember.ReturnType = typeReference;

            methodMember.Attributes = MemberAttributes.Public;

            foreach(IPropertyMap propertyMap in propertyMaps)
            {
                if (!propertyMap.IsCollection)
                {
                    CodeParameterDeclarationExpression parameter = new CodeParameterDeclarationExpression(new CodeTypeReference(propertyMap.DataType), MakeCamelCase(propertyMap.Name));
                    methodMember.Parameters.Add(parameter);
                }
            }

            CodeThisReferenceExpression thisExp = new CodeThisReferenceExpression();
            CodeFieldReferenceExpression contextVar = new CodeFieldReferenceExpression(thisExp, "context");

            CodeExpression[] createParams = new CodeExpression[idPropertyMaps.Count];

            int i = 0;
            foreach(IPropertyMap idPropertyMap in idPropertyMaps)
            {
                CodeArgumentReferenceExpression argExp = new CodeArgumentReferenceExpression(MakeCamelCase(idPropertyMap.Name));
                createParams[i] = argExp;
                i++;
            }

            CodeMethodInvokeExpression newObjectInit = new CodeMethodInvokeExpression(thisExp, GetRepositoryGetByIdentityMethodName(classMap), createParams ) ;

            CodeVariableDeclarationStatement newObjectVarDecl = new CodeVariableDeclarationStatement(classMap.GetName(), MakeCamelCase(classMap.GetName()), newObjectInit) ;
            CodeVariableReferenceExpression newObjectVar = new CodeVariableReferenceExpression(MakeCamelCase(classMap.GetName()));

            methodMember.Statements.Add(newObjectVarDecl);

            foreach(IPropertyMap propertyMap in propertyMaps)
            {
                if (!propertyMap.IsIdentity)
                {
                    if (!propertyMap.IsCollection)
                    {
                        CodeArgumentReferenceExpression argExp = new CodeArgumentReferenceExpression(MakeCamelCase(propertyMap.Name));
                        CodeVariableReferenceExpression propExp = new CodeVariableReferenceExpression(MakeCamelCase(classMap.Name) + "." + propertyMap.Name);
                        CodeAssignStatement assignStatement = new CodeAssignStatement(propExp, argExp);
                        methodMember.Statements.Add(assignStatement);
                    }
                }
            }

            CodeMethodInvokeExpression commitCtx = new CodeMethodInvokeExpression(contextVar, "Commit", new CodeExpression[] {} ) ;

            methodMember.Statements.Add(commitCtx);

            CodeMethodReturnStatement returnStmt = new CodeMethodReturnStatement(newObjectVar) ;

            methodMember.Statements.Add(returnStmt);

            classDecl.Members.Add(methodMember);
        }
开发者ID:BackupTheBerlios,项目名称:puzzle-svn,代码行数:66,代码来源:CodeDomGenerator.cs

示例5: GenerateRepositoryGetByIdentityMethod

        public static void GenerateRepositoryGetByIdentityMethod(IClassMap classMap, CodeTypeDeclaration classDecl, bool tryMethod)
        {
            IList propertyMaps = classMap.GetIdentityPropertyMaps();

            CodeMemberMethod methodMember = new CodeMemberMethod() ;
            if (tryMethod)
                methodMember.Name = GetRepositoryGetByIdentityMethodName(classMap);
            else
                methodMember.Name = GetRepositoryTryGetByIdentityMethodName(classMap);

            CodeTypeReference typeReference = new CodeTypeReference(classMap.GetName());
            methodMember.ReturnType = typeReference;

            methodMember.Attributes = MemberAttributes.Public;

            foreach(IPropertyMap propertyMap in propertyMaps)
            {
                CodeParameterDeclarationExpression parameter = new CodeParameterDeclarationExpression(new CodeTypeReference(propertyMap.DataType), MakeCamelCase(propertyMap.Name));
                methodMember.Parameters.Add(parameter);
            }

            CodeThisReferenceExpression thisExp = new CodeThisReferenceExpression();
            CodeFieldReferenceExpression contextVar = new CodeFieldReferenceExpression(thisExp, "context");

            CodeVariableDeclarationStatement dummyObjectVarDecl = new CodeVariableDeclarationStatement(classMap.GetName(), "identityObject") ;
            CodeVariableReferenceExpression dummyObjectVar = new CodeVariableReferenceExpression("identityObject");

            CodeObjectCreateExpression dummyObjectCreateExpr = new CodeObjectCreateExpression(typeReference, new CodeExpression[] {} );

            CodeAssignStatement assignDummyStatement = new CodeAssignStatement(dummyObjectVar, dummyObjectCreateExpr);

            methodMember.Statements.Add(dummyObjectVarDecl);
            methodMember.Statements.Add(assignDummyStatement);

            foreach(IPropertyMap propertyMap in propertyMaps)
            {
                CodeArgumentReferenceExpression argExp = new CodeArgumentReferenceExpression(MakeCamelCase(propertyMap.Name));
                CodeVariableReferenceExpression propExp = new CodeVariableReferenceExpression("identityObject" + "." + propertyMap.Name);
                CodeAssignStatement assignStatement = new CodeAssignStatement(propExp, argExp);
                methodMember.Statements.Add(assignStatement);
            }

            CodeTypeOfExpression typeOfExp = new CodeTypeOfExpression(typeReference) ;
            CodeMethodInvokeExpression newObjectInit = null;
            if (tryMethod)
                newObjectInit = new CodeMethodInvokeExpression(contextVar, "GetObjectById", new CodeExpression[] { dummyObjectVar, typeOfExp } ) ;
            else
                newObjectInit = new CodeMethodInvokeExpression(contextVar, "TryGetObjectById", new CodeExpression[] { dummyObjectVar, typeOfExp } ) ;

            CodeCastExpression castExp = new CodeCastExpression(typeReference, newObjectInit) ;

            CodeVariableDeclarationStatement newObjectVarDecl = new CodeVariableDeclarationStatement(classMap.GetName(), MakeCamelCase(classMap.GetName()), castExp) ;
            CodeVariableReferenceExpression newObjectVar = new CodeVariableReferenceExpression(MakeCamelCase(classMap.GetName()));

            methodMember.Statements.Add(newObjectVarDecl);

            CodeMethodReturnStatement returnStmt = new CodeMethodReturnStatement(newObjectVar) ;

            methodMember.Statements.Add(returnStmt);

            classDecl.Members.Add(methodMember);
        }
开发者ID:BackupTheBerlios,项目名称:puzzle-svn,代码行数:62,代码来源:CodeDomGenerator.cs

示例6: GuidMustBeTemporaryIdentity

        private bool GuidMustBeTemporaryIdentity(Type type, IClassMap classMap)
        {
            IList idPropertyMaps = classMap.GetIdentityPropertyMaps();
            if (idPropertyMaps.Count > 1)
                return true;

            //should only be one id prop..
            foreach (IPropertyMap propertyMap in idPropertyMaps)
            {
                Type propType = type.GetProperty(propertyMap.Name).PropertyType;
                if (propertyMap.ReferenceType != ReferenceType.None)
                {
                    IClassMap refClassMap = this.Context.DomainMap.MustGetClassMap(propType);
                    return GuidMustBeTemporaryIdentity(propType, refClassMap);
                }
                else
                {
                    if (!propType.IsAssignableFrom(typeof(Guid)))
                        return true;
                }
            }
            return false;
        }
开发者ID:BackupTheBerlios,项目名称:puzzle-svn,代码行数:23,代码来源:DefaultObjectManager.cs

示例7: GetPrimaryKey

		/// <summary>
		/// Gets the primary key of a class.
		/// </summary>
		/// <param name="classMap">The class map.</param>
		/// <returns></returns>
		public static IPropertyMap GetPrimaryKey(IClassMap classMap)
		{
			ArrayList primary = classMap.GetIdentityPropertyMaps();
			if (primary.Count != 1)
			{
				throw new Exception("Wrong primary keys count for class " + classMap.Name + ": " + primary.Count);
			}

			return (IPropertyMap) primary[0];
		}
开发者ID:Dawn-of-Light,项目名称:Puzzle.NET,代码行数:15,代码来源:ClassUtility.cs


注:本文中的IClassMap.GetIdentityPropertyMaps方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。