This is a migrated thread and some comments may be shown as answers.

Multiple Field Identity Problem

2 Answers 70 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dave
Top achievements
Rank 1
Dave asked on 18 Jan 2012, 11:24 AM
Hi there!

I have a table with only two uniqueidentifier-colums. It's the UserInRoles-table.

My mapping is the following:
private MappingConfiguration<ProChristFluentUserInRole> MapProChristUserInRoleTable()
        {
            var tableMapping = new MappingConfiguration<ProChristFluentUserInRole>();
            tableMapping.MapType().ToTable("ProChristUsersInRoles");
 
            tableMapping.HasIdentity(KeyGenerator.Verify);
 
            tableMapping.HasProperty(t => t.UserId).HasColumnType("uniqueidentifier").IsNotNullable();
            tableMapping.HasProperty(t => t.RoleId).HasColumnType("uniqueidentifier").IsNotNullable();
 
            return tableMapping;
        }

The definition of the class and the id:
public class ProChristFluentUserInRoleIdentity : IObjectId
    {
        public Guid UserId { get; set; }
 
        public Guid RoleId { get; set; }
 
        public ProChristFluentUserInRoleIdentity()
        {
            UserId = Guid.NewGuid();
            RoleId = Guid.NewGuid();
        }
 
        public ProChristFluentUserInRoleIdentity(string s)
        {
            UserId = Guid.NewGuid();
            RoleId = Guid.NewGuid();
 
            var parts = s.Split('*');
 
            Guid tUserId;
            if (Guid.TryParse(parts[0], out tUserId))
            {
                UserId = tUserId;   
            }
 
            Guid tRoleId;
            if (Guid.TryParse(parts[1], out tRoleId))
            {
                RoleId = tRoleId;
            }
        }
 
        public override bool Equals(object o)
        {
            if (this == o) return true;
            if (!(o is ProChristFluentUserInRoleIdentity)) return false;
            var id = (ProChristFluentUserInRoleIdentity)o;
            if (UserId != id.UserId) return false;
            if (RoleId != id.RoleId) return false;
            return true;
        }
 
        public override int GetHashCode()
        {
            var result = 0;
            if (UserId != Guid.Empty)
                result += UserId.GetHashCode();
            if (RoleId != Guid.Empty)
                result += RoleId.GetHashCode();
            return result;
        }
 
        public override string ToString()
        {
            var buffer = new System.Text.StringBuilder();
            buffer.Append(UserId).Append('*');
            buffer.Append(RoleId);
            return buffer.ToString();
        }
    }
 
    [Persistent(Identity = typeof(ProChristFluentUserInRoleIdentity))]
    public class ProChristFluentUserInRole
    {
        /// <summary>
        /// Gets or sets the user-Id.
        /// </summary>
        /// <value>
        /// The user-Id.
        /// </value>
        public Guid UserId { get; set; }
 
        /// <summary>
        /// Gets or sets the role-Id.
        /// </summary>
        /// <value>
        /// The role-Id.
        /// </value>
        public Guid RoleId { get; set; }
    }

But, when I try to make a request, I get the following error:
[DataStoreException: Count(*) query failed: Telerik.OpenAccess.RT.sql.SQLException: Invalid column name 'ProChristUsersInRoles_id'.
Statement(s) could not be prepared.
   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeQuery()
   at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeQuery()
   at OpenAccessRuntime.Relational.RelationalStorageManager.executeCount(RelationalCompiledQuery cq, QueryParameters parameters)
SELECT COUNT(1) FROM ( SELECT a.[ProChristUsersInRoles_id] AS COL1, a.[RoleId] AS COL2, a.[UserId] AS COL3 FROM [ProChristUsersInRoles] a WHERE a.[UserId] = ?                       AND a.[RoleId] = ?                        ) AS TMP_COUNT

That is right, because there's no column with name: ProChristUsersInRoles_id
I've tried different KeyGenerator-Types, but without any luck.

I don't know how to solve this problem. Can you help me, please?

Thanks in advance, Dieter

2 Answers, 1 is accepted

Sort by
0
Dave
Top achievements
Rank 1
answered on 18 Jan 2012, 01:59 PM
Ok, I've changed the class to:
[Persistent(Identity = typeof(ID))]
   public class ProChristFluentUserInRole
   {
       /// <summary>
       /// Gets or sets the user-Id.
       /// </summary>
       /// <value>
       /// The user-Id.
       /// </value>
       public Guid UserId { get; set; }
 
       /// <summary>
       /// Gets or sets the role-Id.
       /// </summary>
       /// <value>
       /// The role-Id.
       /// </value>
       public Guid RoleId { get; set; }
 
       public class ID : IObjectId
       {
           public Guid UserId { get; set; }
 
           public Guid RoleId { get; set; }
 
           public ID()
           {
               UserId = Guid.NewGuid();
               RoleId = Guid.NewGuid();
           }
 
           public ID(string s)
           {
               UserId = Guid.NewGuid();
               RoleId = Guid.NewGuid();
 
               var parts = s.Split('*');
 
               Guid tUserId;
               if (Guid.TryParse(parts[0], out tUserId))
               {
                   UserId = tUserId;
               }
 
               Guid tRoleId;
               if (Guid.TryParse(parts[1], out tRoleId))
               {
                   RoleId = tRoleId;
               }
           }
 
           public override bool Equals(object o)
           {
               if (this == o) return true;
               if (!(o is ID)) return false;
               var id = (ID)o;
               if (UserId != id.UserId) return false;
               if (RoleId != id.RoleId) return false;
               return true;
           }
 
           public override int GetHashCode()
           {
               var result = 0;
               if (UserId != Guid.Empty)
                   result += UserId.GetHashCode();
               if (RoleId != Guid.Empty)
                   result += RoleId.GetHashCode();
               return result;
           }
 
           public override string ToString()
           {
               var buffer = new System.Text.StringBuilder();
               buffer.Append(UserId).Append('*');
               buffer.Append(RoleId);
               return buffer.ToString();
           }
       }
   }
but still the same problem
0
Thomas
Telerik team
answered on 20 Jan 2012, 02:01 PM
Hi Dieter,

you need to mark the fields that should form the identity:

var mapping = new MappingConfiguration<Simple>();

mapping.MapType();

mapping.HasProperty(x => x.Id).IsIdentity();


Here, the HasProperty() marks the property as persistent, and then tells the configuration that this field is an identity field.

All the best,
Thomas
the Telerik team

SP1 for Q3’11 of Telerik OpenAccess ORM is available for download

Tags
General Discussions
Asked by
Dave
Top achievements
Rank 1
Answers by
Dave
Top achievements
Rank 1
Thomas
Telerik team
Share this question
or