简体   繁体   English

CreateUserAndAccount方法-SimpleMembership Provider

[英]CreateUserAndAccount method - SimpleMembership Provider

I have 2 questions: 我有两个问题:

  1. Why am I getting that exception? 我为什么要得到这个例外? I want to create a row in my User Table (it has 6 columns: Name, Role, Email, Group, Id, SoftwareVersion) and in the Membership table. 我想在用户表中创建一行(它有6列:名称,角色,电子邮件,组,Id,SoftwareVersion)和成员资格表中。 The primary key is the pair Id-SoftwareVersion. 主键是Id-SoftwareVersion对。 The code: 编码:

code

What's wrong? 怎么了?

  1. Is it possible add more row (with CreateUserAndAccount) by changing the id? 是否可以通过更改ID添加更多行(使用CreateUserAndAccount)? Right? 对? Example: try to add a row with "Administrator" as UserName when an entry already exists in the DB with the same name (but I remember the primary key is the pair Id-SoftwareVersion). 示例:当数据库中已经存在一个具有相同名称的条目时,尝试添加一个以“ Administrator”作为用户名的行(但我记得主键是Id-SoftwareVersion对)。

My User class: 我的用户类别:

public partial class User
{
    public User()
    {
        this.dfcs = new HashSet<Dfc>();
        this.fids = new HashSet<Fid>();
        this.histroyDeliverRequests = new HashSet<Histroyrequest>();
        this.histroyProposalRequests1 = new HashSet<Histroyrequest>();
    }

    public string Name { get; set; }
    public string Role { get; set; }
    public string Email { get; set; }
    public string Group { get; set; }
    public int Id { get; set; }
    public short SoftwareVersion { get; set; }

    public virtual ICollection<Dfc> dfcs { get; set; }
    public virtual ICollection<Fid> fids { get; set; }
    public virtual ICollection<Histroyrequest> histroyDeliverRequests { get; set; }
    public virtual ICollection<Histroyrequest> histroyProposalRequests1 { get; set; }
    public virtual Software Software { get; set; }
}

我认为您在插入用户表时应该省略ID,因为我认为插入新记录时ID会自动递增?

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

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