Hello, I have created my database within SQL Server Managment and added Relationships to Tables, for example:
- Images (Table) UserID (The ID for the User who uploaded the Image)
So the UserID Column is linked to the ID (PrimaryKey) of the Users Table, as that user is related to that column.
However, I may have set these up incorrectly as you can see from the errors below.
Also seem to be getting another issue when creating the Hash for the entered Password, the user enters their password into a TextBox which updates a property called ClearPassword, then the Hash doesn't need a SET value as it is a readonly property which generates the Hash, I have provided my User class below:
//------------------------------------------------------------------------------ // <auto-generated> // This code was generated from a template. // // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace PhotoManagement.EntityData { using System; using System.Collections.Generic; using System.Security; public partial class User { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public User() { this.Images = new HashSet<Image>(); this.Sales = new HashSet<Sale>(); } public int ID { get; set; } public string FName { get; set; } public string LName { get; set; } public string Email { get; set; } public string ClearPassword { get; set; } public string Hash { get { return Common.Security.HashGenerator.CalculateHash(ClearPassword, Salt); } } public string passCheck { get; set; } public string Salt { get { return Common.Security.KeyGenerator.GetUniqueKey(64); } } public System.DateTime DateCreated { get; set; } public string Address { get; set; } public System.DateTime DateLastAccessed { get; set; } public string AuthCode { get; set; } public int Role { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection<Image> Images { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection<Sale> Sales { get; set; } } }
Errors:
An exception of type 'System.Data.Entity.Core.MetadataException' occurred in EntityFramework.dll but was not handled in user code Additional information: Schema specified is not valid. Errors: The relationship 'PhotoManagmentModel.FK_ImagesUserID_UsersID' was not loaded because the type 'PhotoManagmentModel.User' is not available. The following information may be useful in resolving the previous error: The property 'Hash' of type 'PhotoManagement.EntityData.User' in the assembly 'PhotoManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' cannot be used as a scalar property because it does not have both a getter and setter. The relationship 'PhotoManagmentModel.FK_SalesSaleID_UsersID' was not loaded because the type 'PhotoManagmentModel.User' is not available. The following information may be useful in resolving the previous error: The property 'Hash' of type 'PhotoManagement.EntityData.User' in the assembly 'PhotoManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' cannot be used as a scalar property because it does not have both a getter and setter.
Here is the Project: Download Here