I've been working on a simple Dropbox-like app, to learn some ASP.NET MVC. But even before getting a page working decently I've gotten stuck, and there's so much info out there I can't see the forest for the trees anymore.
My situation:
I want to show on a page all the files in a certain folder belonging to a certain person. I've designed my database beforehand and then generated a Code First EF model from that. The relevant part of the database is below. Note that AspNetUsers
is part of MVC5 Identity. Linking Identity
to my own tables seems to be the hardest part, since the tables belonging to Identity
are implemented in IdentityModels, while my tables are implemented in TADModels.
I've been following various tutorials on this page, but can't seem to find anything that helps me accomplish what I need. I'm basically just trying to execute the following query:
SELECT f.FileName, f.FileSize
FROM Files f
INNER JOIN FileTree ft ON ft.FolderID = f.FolderID
INNER JOIN AspNetUsers u ON ft.UserID = u.Id
WHERE u.id = @id AND ft.FolderPath = @path;
According to one of the aforementioned tutorials, I'm supposed to be able to do something along the lines of:
namespace TAD.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
[Table("FileTree")]
public partial class FileTree
{
[Key]
public string FolderID { get; set; }
[Required]
[StringLength(128)]
public string UserID { get; set; }
[Required]
[StringLength(255)]
public string FolderName { get; set; }
[Required]
[StringLength(255)]
public string FolderPath { get; set; }
public virtual ICollection<File> Files { get; set; }
public virtual ApplicationUser user { get; set; }
}
}
The Files Collection is supposed to find the files associated with the path, and user is supposed to find the user associated with the path. But during Scaffolding I get errors along the lines of TAD.Models.IdentityUserRole: EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType'
. Which I suppose is happening because of ApplicationUSer user
This question seems very confusing, even to me. I simply don't know what I'm looking for. The tutorials I mentioned present situations too simple for my needs, while other info is much too advanced.
EDIT: This is the File Model:
namespace TAD.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
public partial class File
{
[Key]
public string FileID { get; set; }
[Required]
[StringLength(128)]
public string UserID { get; set; }
[Required]
[StringLength(128)]
public string FolderID { get; set; }
[Required]
[StringLength(255)]
public string FileName { get; set; }
public decimal FileSize { get; set; }
public bool IsPublic { get; set; }
public virtual ApplicationUser user { get; set; }
public virtual FileTree folder { get; set; }
}
}