3

With MVC EF code first, a new project can come with account functionality (login, register, etc). I changed the DB connection string from pointing to the mdf file in the App_Data folder to have the connection string point to a SQL Server instance. The ASP.NET specific tables were created in the SQL Server Instance.

Now when this following line of auto generated code runs:

var result = await SignInManager.PasswordSignInAsync(model.Email,
    model.Password, model.RememberMe, shouldLockout: false);

It throws an exception:

The specified cast from a materialized 'System.Guid' type to the 'System.String' type is not valid.

The DB fields and domain model are Guids. Any help would be appreciated.

Thanks

1
  • 2
    this error is telling you that EF materialized an Guid value from database, while in the required object type for this field is a string. I don't know what this line of code exactly does, but I suspect your POCO classes do not match the database schema or your model configuration is off. Mar 5, 2016 at 6:05

1 Answer 1

3

In my case, my entity was using a Guid as an ID, but in the database the ID was nvarchar(300), I solved the problem by changing the nvarchar(300) to uniqueidentifier, but dont do this without knowing the effect that this could take on your database/application, in my case it was simple and that worked fine.

I hope this helps if someone else have the same problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.