Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BulkInsert Object reference not set to an instance of an object. #28

Closed
myesn opened this issue Mar 17, 2018 · 8 comments
Closed

BulkInsert Object reference not set to an instance of an object. #28

myesn opened this issue Mar 17, 2018 · 8 comments
Assignees

Comments

@myesn
Copy link

myesn commented Mar 17, 2018

Here is my code:

image

image

    class Program
    {
        static async Task Main(string[] args)
        {
            //var summary = BenchmarkRunner.Run<DapperTest>();

            Stopwatch sw = Stopwatch.StartNew();

            await DapperBulkInsert();

            sw.Stop();

            Console.WriteLine($"time consuming: {sw.ElapsedMilliseconds} ms\r\noperations done");

            Console.ReadKey();
        }

        static async Task DapperBulkInsert()
        {
            DapperPlusManager.Entity<UserToken>()
                .Table($"{nameof(UserToken)}s")
                .Identity(x => x.Id);

            Console.WriteLine("connect to database");
            using (var conn = new MySqlConnection("server=192.168.110.130;database=usercenterdb;uid=root;pwd=P@ssw0rd;charset='latin1';sslmode=none;"))
            {
                try
                {
                    await conn.OpenAsync();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"error: {ex.Message}");
                    return;
                }

                Console.WriteLine("insert items");
                var rows = Enumerable.Range(0, 100).Select(x => new UserToken()
                {
                    Id = Guid.NewGuid(),
                    UserId = Guid.Parse("08d56d0b-f8fb-bed7-47d4-332e74ef4ef1")
                });

                try
                {
                    conn.BulkInsert(rows);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }
    }

    public class UserToken
    {
        public UserToken()
        {
            Expiration = LoginTime.AddHours(2d);
        }

        public Guid Id { get; set; }
        public DateTime Expiration { get; set; }
        public int LoginProvider { get; set; } = 0;
        public DateTime LoginTime { get; set; } = DateTime.Now;
        public Guid UserId { get; set; }
        public int State { get; set; } = 0;
    }

Then I run this program and get the following result:

image

How can i fix it, thank you.

@JonathanMagnan JonathanMagnan self-assigned this Mar 17, 2018
@JonathanMagnan
Copy link
Member

Hello @myesn ,

Thank you for reporting. The MySqlConnector is not yet supported.

I believe there is an issue in our code that detects the current provider might be https://www.nuget.org/packages/MySql.Data/ and then the error throws an error later instead of the traditional unsupported provider error.

We will look at the difficulty to support this new provider at the beginning of next week.

Best Regards,

Jonathan

@myesn
Copy link
Author

myesn commented Mar 20, 2018

Thank you for reply, I switch to Mysql.data(version: 8.0.10-rc), then program throw this error:
image

@JonathanMagnan
Copy link
Member

Hello @myesn ,

The v1.3.14 has been released.

A conditional compilation debug was missing and the wrong code was taken when reading MySQL.

Let me know if that works correctly with the new version.

Best Regards,

Jonathan

@myesn
Copy link
Author

myesn commented Mar 21, 2018

I use Z.Dapper.Plus(version: 1.3.14) and MySql.Data(version: 8.0.10-rc),but program also throw a error
image

image

@JonathanMagnan
Copy link
Member

Hello @myesn ,

Do you think you could provide us a project with this error?

That's normally due to something in your entities or your mapping so we cannot reproduce it on our side. You can send it in private here: info@zzzprojects.com

Best Regards,

Jonathan

@myesn
Copy link
Author

myesn commented Mar 23, 2018

Mail has been sent

@JonathanMagnan
Copy link
Member

Hello @myesn ,

Unfortunately, our code will not work with the Identity as a GUID. Our code expects the column to be an identity column and not a GUID which causes the error.

You can make the code work with your code by removing it from the mapping:

 DapperPlusManager.Entity<UserToken>()
                .Table($"{nameof(UserToken)}s");

Let me know if that answered your question correctly.

Best Regards,

Jonathan

@myesn
Copy link
Author

myesn commented Mar 28, 2018

It works now, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants