0

I am trying to follow the tutorial listed here: Link

And when I insert the below code

 public ApplicationUser()
    {
        UserUpload = new HashSet(); } public ICollection UserUpload { get; set; } 
    }

into the ApplicationUser class of IdentityModels.cs I get the folloiwing error:

'Cannot implicitly convert type 'System.Collections.Generic.HashSet' to 'System.Collections.Generic.ICollection'. An explicit conversion exists (Are you missing a cast?).

I am very new to programming and have no idea what to do! Any help would be appreciated, thanks. Whole code is below. It's built on MVC 5 in VS 2015.

using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System.Collections.Generic;

namespace ENUSecretShare.Models
{
    // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
    public class ApplicationUser : IdentityUser

    {

        public string FName { get; set; }

        public string LName { get; set; }

        public int nValue { get; set; }

        public int tValue { get; set; }


        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            return userIdentity;

        }

    public ApplicationUser()
        {
            UserUpload = new HashSet(); } public ICollection UserUpload { get; set; } 
    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
        }

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
    }
}
tereško
  • 58,060
  • 25
  • 98
  • 150
Keith Thomson
  • 63
  • 4
  • 9

2 Answers2

0

Don't have my laptop here now but does it even compile? U use System.Collections.Generic but there is nothing generic about UserUploads in ur code...

Something like this should work:

ICollection<string> UserUploads = new HashSet<string>();

Just exchange string with ur type.

Helikaon
  • 1,490
  • 13
  • 30
-1

This:

public class ApplicationUser : IdentityUser
{
    public ApplicationUser()
    {
        this.UserImages = new HashSet<UserImage>();
    }

    public ICollection<UserImage> UserImages { get; set; }

    // continue below ...
}
joegreentea
  • 325
  • 3
  • 12