4

我在最后一两天做了一些事情来破坏我的申请。

我有一种使用会员提供程序在会员数据库中创建新用户的方法。

例如

 public void Create(Consumer consumer)
    {

        MembershipCreateStatus status;
        if (consumer.UserId == Guid.Empty)
        {
            consumer.UserId = Guid.NewGuid();
        }
        if (consumer.ConsumerId == Guid.Empty)
        {
            consumer.ConsumerId = Guid.NewGuid();
        }
        try
        {
            var membershipUser = Membership.CreateUser(consumer.UserName, consumer.Password, consumer.Email, null, null, consumer.IsApproved, consumer.UserId, out status);
....
}

内部异常是

{“无效的对象名称'dbo.Memberships'。”}

堆栈跟踪是

在 System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior 行为) 在 System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues) 在 System.Data.Objects.ObjectQuery 1.GetResults(Nullable1 forMergeOption)在 System.Data.Objects.ObjectQuery 1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 源)在 System.Data.Objects.ELinq.ObjectQueryProvider.b__1[TResult](IEnumerable1 sequence) at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable1 个查询,Expression queryRoot) 在 System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression) 在 System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source) 在 System .Web.Providers.QueryHelper.GetMembership(MembershipEntities ctx, String applicationName, Guid userId) at System.Web.Providers.DefaultMembershipProvider.Membership_CreateUser(String applicationName, String userName, String password, String salt, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, DateTime& createDate, Boolean uniqueEmail, Int32 passwordFormat, Object& providerUserKey) at System.Web.Providers.DefaultMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved,Plenfy.Api.Models.ConsumerRepository 的 System.Web.Security.Membership.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) 中的对象 providerUserKey, MembershipCreateStatus& status)。在 c:\@Code\Customers\Api\Repository\ConsumerRepository.cs:line 121 中创建(消费者消费者)

我不知道如何解决这个问题。数据库和连接字符串看起来不错,我可以用 EF 连接到它。

谁能建议如何解决这个问题?

4

1 回答 1

-1
try to use 
MembershipCreateStatus status;
        if (consumer.UserId == Guid.Empty)
        {
            consumer.UserId = Guid.NewGuid();
        }
        if (consumer.ConsumerId == Guid.Empty)
        {
            consumer.ConsumerId = Guid.NewGuid();
        }
        try
        {
            var membershipUser = System.Web.Security.Membership.CreateUser(consumer.UserName, consumer.Password, consumer.Email, null, null, consumer.IsApproved, consumer.UserId, out status);
        }
于 2014-04-25T14:16:31.910 回答