IdentityServer / IdentityServer3.EntityFramework

EntityFramework persistence layer for IdentityServer3
Apache License 2.0
68 stars 97 forks source link

Exception while trying to create a client and store it to mysql db #90

Closed omerlh closed 8 years ago

omerlh commented 8 years ago

Hey, I've tried to run the following code:

var context = new ClientConfigurationDbContext(@"Data Source=(LocalDB)\v11.0;  
                                     Initial Catalog=Northwind;  
                                     Integrated Security=True; ");
            var client = new Client
            {
                ClientName = "Silicon-only Client",
                ClientId = "silicon",
                Enabled = true,
                AccessTokenType = AccessTokenType.Reference,

                Flow = Flows.ClientCredentials,

                ClientSecrets = new List<Secret>
                {
                    new Secret("F621F470-9731-4A25-80EF-67A6F7C5F4B8".Sha256())
                },

                AllowedScopes = new List<string>
                {
                    "api1"
                }
            };

            context.Clients.Add(client.ToEntity());
            context.SaveChanges();

I am trying to create some demo data in the storage in order to test my service. When I run this code, the mapping from model to entity failed with the following exception:

{"Missing type map configuration or unsupported mapping.\r\n\r\nMapping types:\r\nClient -> Int32\r\nIdentityServer3.Core.Models.Client -> System.Int32\r\n\r\nDestination path:\r\nClient\r\n\r\nSource value:\r\nIdentityServer3.Core.Models.Client"}

And I can't understand what it try to convert... Could you help? Thanks!

brockallen commented 8 years ago

Is this your issue? https://github.com/IdentityServer/IdentityServer3.EntityFramework/issues/72#issuecomment-180094260

Update to the latest to get the AutoMapper updates: https://github.com/IdentityServer/IdentityServer3.EntityFramework/releases/tag/2.4.1

omerlh commented 8 years ago

Not looking the same exception, I am not sure. I am using the latest version on identityserver entityframework (2.4.1). Automapper version is 4.2.0

brockallen commented 8 years ago

Well, then the only other thing I can think of is that your connection string "Data Source=LocalDB)\v11.0; Initial Catalog=Northwind; Integrated Security=True; " doesn't look anything like a MySql connection string.

omerlh commented 8 years ago

I know that the connection to the storage work, it is failing in the line of the mapping, e.g.:

context.Clients.Add(client.ToEntity());

And the exception is from the mapper...

brockallen commented 8 years ago

And you're using IdSvr 2.4 and EF 2.4.1?

omerlh commented 8 years ago

Yes, that’s what weird…

From: Brock Allen [mailto:notifications@github.com] Sent: Tuesday, February 9, 2016 4:43 PM To: IdentityServer/IdentityServer3.EntityFramework IdentityServer3.EntityFramework@noreply.github.com Cc: Omer Levi Hevroni omerl@soluto.com Subject: Re: [IdentityServer3.EntityFramework] Exception while trying to create a client and store it to mysql db (#90)

And you're using IdSvr 2.4 and EF 2.4.1?

— Reply to this email directly or view it on GitHubhttps://github.com/IdentityServer/IdentityServer3.EntityFramework/issues/90#issuecomment-181896321.

brockallen commented 8 years ago

Ok, not sure then. The only thing I can suggest is comparing your code to the working sample: https://github.com/IdentityServer/IdentityServer3.Samples/tree/master/source/EntityFramework

omerlh commented 8 years ago

I’ve tried that, by the working example doesn’t contain any example of inserting data. I also tried to run the administrative too, but the same error occurred…

brockallen commented 8 years ago

I think it does at startup time: https://github.com/IdentityServer/IdentityServer3.Samples/blob/master/source/EntityFramework/SelfHost/Config/Factory.cs#L24

omerlh commented 8 years ago

Ok, I will give it a try and update here. Thanks!

omerlh commented 8 years ago

Update: I've just cloned the examples repository and tried to run the entity framework examples, but the same error occurred...

brockallen commented 8 years ago

And you created the database with migrations, as we suggest: https://identityserver.github.io/Documentation/docsv2/ef/migrations.html

omerlh commented 8 years ago

I didn't know I should, I just cloned the repo of the examples... Any way even trying to apply the migration result in failure, like this one (on add migration): Unable to generate an explicit migration because the following explicit migrations are pending: [201502141840088_InitialCreate, 201504070215165_v2_0_0, 201511200152080_v2_2_0, 201512191738380_v2_3_0, 201601182228505_v2_4_0]. Apply the pending explicit migrations before attempting to generate a new explicit migration.

brockallen commented 8 years ago

I just cleared my DB and re-ran the migrations on the EF sample and it's all working. It must be some problem in your environment.

omerlh commented 8 years ago

OK, I will try again. Any tips about setting the environment?

Sent from Outlook Mobilehttps://aka.ms/blhgte

On Mon, Feb 22, 2016 at 7:45 AM -0800, "Brock Allen" notifications@github.com<mailto:notifications@github.com> wrote:

I just cleanred my DB and re-ran the migrations on the EF sample and it's all working. It must be some problem in your environment.

Reply to this email directly or view it on GitHubhttps://github.com/IdentityServer/IdentityServer3.EntityFramework/issues/90#issuecomment-187237859.

brockallen commented 8 years ago

No, I used SqlServer LocalDb that comes with VS, and I ran the 3 update-database commands from the sample project.

omerlh commented 8 years ago

Ok, I will give it a try

From: Brock Allen [mailto:notifications@github.com] Sent: Tuesday, February 23, 2016 3:54 PM To: IdentityServer/IdentityServer3.EntityFramework IdentityServer3.EntityFramework@noreply.github.com Cc: Omer Levi Hevroni omerl@soluto.com Subject: Re: [IdentityServer3.EntityFramework] Exception while trying to create a client and store it to mysql db (#90)

No, I used SqlServer LocalDb that comes with VS, and I ran the 3 update-database commands from the sample project.

— Reply to this email directly or view it on GitHubhttps://github.com/IdentityServer/IdentityServer3.EntityFramework/issues/90#issuecomment-187707882.

omerlh commented 8 years ago

Ok, I tried again. Just installed fresh new SQLExpress on my machine, connect to it from visual studio and copied the connection string, which now look like that:

    <add name="IdSvr3Config" connectionString="Data Source=[machine name]\SQLEXPRESS;Initial Catalog=master;Integrated Security=True" providerName="System.Data.SqlClient" />

But, still the same errors when trying to enable migrations or to run the sample. So I really don't know what the problem could be...

omerlh commented 8 years ago

Update: I've managed to run the migration after deleting the migration folder in the example. But, also after migration completed successfully, the same error occurred.

brockallen commented 8 years ago

Did you ever sort this out?

omerlh commented 8 years ago

Nope, I just give up and did not use this...