コード例 #1
0
ファイル: ClassProperty.cs プロジェクト: fake-fur/RepoDb
        /// <summary>
        /// Gets a value whether the current property is a primary property.
        /// </summary>
        /// <returns>True if the current property is a primary.</returns>
        public bool?IsPrimary()
        {
            if (m_isPrimary != null)
            {
                return(m_isPrimary);
            }

            // Primary Attribute
            m_isPrimary = (GetPrimaryAttribute() != null);
            if (m_isPrimary == true)
            {
                return(m_isPrimary);
            }

            // PrimaryMapper
            var classProperty = PrimaryMapper.Get(GetDeclaringType());

            m_isPrimary = (classProperty == this);
            if (m_isPrimary == true)
            {
                return(m_isPrimary);
            }

            // Id Property
            m_isPrimary = string.Equals(PropertyInfo.Name, "id", StringComparison.OrdinalIgnoreCase);
            if (m_isPrimary == true)
            {
                return(m_isPrimary);
            }

            // Type.Name + Id
            m_isPrimary = string.Equals(PropertyInfo.Name, string.Concat(GetDeclaringType().Name, "id"), StringComparison.OrdinalIgnoreCase);
            if (m_isPrimary == true)
            {
                return(m_isPrimary);
            }

            // Mapping.Name + Id
            m_isPrimary = string.Equals(PropertyInfo.Name, string.Concat(ClassMappedNameCache.Get(GetDeclaringType()), "id"), StringComparison.OrdinalIgnoreCase);
            if (m_isPrimary == true)
            {
                return(m_isPrimary);
            }

            // Return false
            return(m_isPrimary = false);
        }
コード例 #2
0
 /// <summary>
 /// Defines the data entity type primary property (via <see cref="Field"/> object).
 /// </summary>
 /// <param name="field">The instance of <see cref="Field"/> object to be mapped.</param>
 /// <param name="force">A value that indicates whether to force the mapping. If one is already exists, then it will be overwritten.</param>
 /// <returns>The current instance.</returns>
 public EntityMapFluentDefinition <TEntity> Primary(Field field,
                                                    bool force)
 {
     PrimaryMapper.Add <TEntity>(field, force);
     return(this);
 }
コード例 #3
0
 /// <summary>
 /// Defines the data entity type primary property.
 /// </summary>
 /// <param name="expression">The expression to be parsed.</param>
 /// <param name="force">A value that indicates whether to force the mapping. If one is already exists, then it will be overwritten.</param>
 /// <returns>The current instance.</returns>
 public EntityMapFluentDefinition <TEntity> Primary(Expression <Func <TEntity, object> > expression,
                                                    bool force)
 {
     PrimaryMapper.Add <TEntity>(expression, force);
     return(this);
 }
コード例 #4
0
 /// <summary>
 /// Defines the data entity type primary property (via property name).
 /// </summary>
 /// <param name="propertyName">The name of the class property to be mapped.</param>
 /// <param name="force">A value that indicates whether to force the mapping. If one is already exists, then it will be overwritten.</param>
 /// <returns>The current instance.</returns>
 public EntityMapFluentDefinition <TEntity> Primary(string propertyName,
                                                    bool force)
 {
     PrimaryMapper.Add <TEntity>(propertyName, force);
     return(this);
 }
コード例 #5
0
 protected IPrimaryOptions <T> Primary(Expression <Func <T, object> > expression)
 {
     PrimaryMapper.Add <T>(expression);
     return(new PrimaryOptions <T>(expression));
 }