I am creating ASP.Net web application (.Net Framework) with individual authentication having those projects: 1- Domain project containing base class:
public class IdentityUser<TKey, TUserLogin, TUserRole, TUserClaim> : IUser<TKey>
where TUserLogin : IdentityUserLogin<TKey>
where TUserRole : IdentityUserRole<TKey>
where TUserClaim : IdentityUserClaim<TKey>
{
public virtual TKey Id { get; set; }
public virtual string UserName { get; set; }
public virtual string PasswordHash { get; set; }
public virtual string SecurityStamp { get; set; }
}
2- DAl Project containing user Class
[TableAttribute(Name = "dbo.IdentityUsers")]
public partial class IdentityUser: IdentityUser<string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>,
INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
private string _Id;
[ColumnAttribute(Name = "Id", Storage = "_Id", DbType = "NVarChar(128) NOT NULL", CanBeNull = false, IsPrimaryKey = true, UpdateCheck = UpdateCheck.Never)]
public override string Id
{
get
{
return _Id;
}
set
{
if ((_Id != value))
{
OnIdChanging(value);
SendPropertyChanging();
_Id = value;
SendPropertyChanged("Id");
OnIdChanged();
}
}
}
private string _UserName;
[ColumnAttribute(Name = "UserName", Storage = "_UserName", DbType = "NVarChar(256) NOT NULL", CanBeNull = false, UpdateCheck = UpdateCheck.Never)]
public override string UserName
{
get
{
return _UserName;
}
set
{
if ((_UserName != value))
{
OnUserNameChanging(value);
SendPropertyChanging();
_UserName = value;
SendPropertyChanged("UserName");
OnUserNameChanged();
}
}
}
private string _PasswordHash;
[ColumnAttribute(Name = "PasswordHash", Storage = "_PasswordHash", DbType = "NVarChar(MAX)", UpdateCheck = UpdateCheck.Never)]
public override string PasswordHash
{
get
{
return _PasswordHash;
}
set
{
if ((_PasswordHash != value))
{
OnPasswordHashChanging(value);
SendPropertyChanging();
_PasswordHash = value;
SendPropertyChanged("PasswordHash");
OnPasswordHashChanged();
}
}
}
private string _SecurityStamp;
[ColumnAttribute(Name = "SecurityStamp", Storage = "_SecurityStamp", DbType = "NVarChar(MAX)", UpdateCheck = UpdateCheck.Never)]
public override string SecurityStamp
{
get
{
return _SecurityStamp;
}
set
{
if ((_SecurityStamp != value))
{
OnSecurityStampChanging(value);
SendPropertyChanging();
_SecurityStamp = value;
SendPropertyChanged("SecurityStamp");
OnSecurityStampChanged();
}
}
}
public IdentityUser()
{
_Id = Guid.NewGuid().ToString();
}
public IdentityUser(string userName) : this()
{
_UserName = userName;
}
}
and DataContext Class
[Database]
public class MahrousSoftDataContext : DataContext
{
#region Members
private static MappingSource mappingSource = new AttributeMappingSource();
#endregion Members
#region Properties
public Table<IdentityUser> IdentityUsers
{
get
{
return GetTable<IdentityUser>();
}
}
#endregion Properties
#region Constructors
public MahrousSoftDataContext() :
base(System.Configuration.ConfigurationManager.ConnectionStrings["mamsdbConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}
public MahrousSoftDataContext(string connection) : base(connection, mappingSource)
{
OnCreated();
}
public MahrousSoftDataContext(System.Data.IDbConnection connection) : base(connection, mappingSource)
{
OnCreated();
}
public MahrousSoftDataContext(string connection, MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public MahrousSoftDataContext(System.Data.IDbConnection connection, MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
#endregion Constructors
}
3- BLL Project containing usermanger and applicationusermanger
4- web project
the problem is when i register a new user i get this exception
System.InvalidOperationException occurred HResult=0x80131509 Message=Class member IdentityUser`5.UserName is unmapped. Source= StackTrace:
at System.Data.Linq.Mapping.AttributedMetaType.GetDataMember(MemberInfo mi)
at System.Data.Linq.CommonDataServices.GetKeyFromPredicate(MetaType type, Dictionary2 keys, Expression mex, Expression vex)
at System.Data.Linq.CommonDataServices.GetKeysFromPredicate(MetaType type, Dictionary
2 keys, Expression expr)
at System.Data.Linq.CommonDataServices.GetKeyValues(MetaType type, LambdaExpression predicate)
at System.Data.Linq.CommonDataServices.GetCachedObject(Expression query)
at System.Data.Linq.SqlClient.SqlProvider.GetCachedResult(Expression query)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.Table1.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.Single[TSource](IQueryable
1 source, Expression1 predicate)
at MA.MahrousSoft.DAL.Tables.Identity.IdentityUserTable
1.SelectByUserName(MahrousSoftDataContext db, String username) in IdentityUserTable.cs:line 26
at MA.MahrousSoft.Stores.Identity.IdentityUserStore1.FindByNameAsync(MahrousSoftDataContext db, String userName) in IdentityUserStore.cs:line 57
at MA.MahrousSoft.Stores.Identity.IdentityUserStore
1.FindByNameAsync(String userName) in IdentityUserStore.cs:line 48
at Microsoft.AspNet.Identity.UserManager2.FindByNameAsync(String userName)
at Microsoft.AspNet.Identity.UserValidator
2.d__4.MoveNext()
User contributions licensed under CC BY-SA 3.0