简体   繁体   English

使用usermanager编辑用户个人资料图像

[英]edit user profile image with usermanager

I'm following this tutorial to add profile picture once account create. 创建帐户后,我将按照本教程添加个人资料图片。

that edit has following snippet, 该修改包含以下代码段,

Student student = db.Students.Include(s => s.Files).SingleOrDefault(s => s.ID == id);

In above example it applied to table call Student in my case I want to go with AspNetUser table , but then I have to go with UserManger feature , Once I try to Include a file then it popping that error in compile time. 在上面的示例中,在我的情况下,它适用于表调用Student ,我想使用AspNetUser table,但是然后我必须使用UserManger功能,一旦尝试Include文件,它就会在编译时弹出该错误。

But in my scenario I'm trying to include in AspNetUser or UserManager 但是在我的情况下,我试图包含在AspNetUserUserManager

So to populate uploaded picture. 因此要填充上传的图片。 I need include following code in user manager 我需要在用户管理器中include以下代码

var user = await UserManager.Include(s => s.Files).FindByIdAsync(userid);

but then getting following error 但随后出现以下错误

'ApplicationUserManager' does not contain a definition for 'Include' and no extension method 'Include' accepting a first argument of type 'ApplicationUserManager' 'ApplicationUserManager'不包含'Include'的定义,也没有扩展方法'Include'接受类型为'ApplicationUserManager'的第一个参数

How to ignore and include files 如何忽略和包含文件

EDIT: 编辑:

These are the changes I've done in Model classes 这些是我在Model类中所做的更改

File 文件

public class File
{
    public int FileId { get; set; }
    ..

    public virtual ApplicationUser UserManager { get; set; }
}

FilePath 文件路径

public class FilePath
{
    public int FilePathId { get; set; }
    ..

    public virtual ApplicationUser UserManager { get; set; }
}

ApplicationUser ApplicationUser

public class ApplicationUser : IdentityUser
{
        ....

        public virtual ICollection<File> Files { get; set; }
        public virtual ICollection<FilePath> FilePaths { get; set; }

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
    {
       ....
    }
}

AspNetUser AspNetUser

public partial class AspNetUser
{

    public AspNetUser()
    {
       ..
    }
    ....

    public virtual ICollection<File> Files { get; set; }
    public virtual ICollection<FilePath> FilePaths { get; set; }
}

then try to add migration to the project by typing the following into the PMC: 然后尝试通过在PMC中键入以下内容来向项目添加迁移:

add-migration File

add-migration FilePaths

then getting following error in console 然后在控制台中出现以下错误

No migrations configuration type was found in the assembly 'Project_Name'. 在程序集“ Project_Name”中找不到迁移配置类型。 (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration). (在Visual Studio中,您可以使用Package Manager控制台中的Enable-Migrations命令来添加迁移配置)。


then I typed the following into the PMC: 然后我在PMC中输入以下内容:

Enable-Migrations project_name.Models.sampleEntityFrameworkEntities

then I got following error in console 然后我在控制台中出现以下错误

Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. 不支持创建DbModelBuilder或从使用Database First或Model First创建的DbContext编写EDMX。 EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel. 只能从创建的Code First DbContext中获得EDMX,而不使用现有的DbCompiledModel。


then I try to migrate Files and FilesPath using following code 然后我尝试使用以下代码迁移FilesFilesPath

add-migration File

add-migration FilePaths

Get error in console 在控制台中出现错误

Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. 不支持创建DbModelBuilder或从使用Database First或Model First创建的DbContext编写EDMX。 EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel. 只能从创建的Code First DbContext中获得EDMX,而不使用现有的DbCompiledModel。

If I understood you correctly you're trying to follow the guide but using ASP.NET Identity. 如果我正确理解了您,则尝试使用该指南,但使用ASP.NET Identity。 ASP.NET Identity is a unique system with its own classes and DBContext. ASP.NET Identity是具有其自己的类和DBContext的唯一系统。 In order to add new fields to the user you need to modify ApplicationUser class. 为了向用户添加新字段,您需要修改ApplicationUser类。 Just add your property to this class and apply migration if needed. 只需将您的媒体资源添加到此类,然后根据需要应用迁移即可。 This will add a new column to the AspNetUser. 这将向AspNetUser添加一个新列。 Then add your field to the ViewModel (if any) and to other logic that is required to work with your field. 然后将您的字段添加到ViewModel(如果有)和使用该字段所需的其他逻辑中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM