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

DatabaseGeneratedOption.None not working #304

Open
denovellis opened this issue Apr 24, 2024 · 1 comment
Open

DatabaseGeneratedOption.None not working #304

denovellis opened this issue Apr 24, 2024 · 1 comment

Comments

@denovellis
Copy link

denovellis commented Apr 24, 2024

Hi,

I've encountered a problem where, even though DatabaseGeneratedOption is set to None, the system is still attempting to perform an insertion with an auto-increment value instead of using the provided value for the insert.

Steps to Reproduce:
Configure a model with DatabaseGeneratedOption set to None.
Attempt to insert a record into the database by explicitly providing a value for the primary key.
Observe that an auto-increment value is being used instead.

Expected Behavior:
The system should use the value provided for the insertion, as DatabaseGeneratedOption.None suggests that the value will not be automatically generated by the database.

Generated sql (found via profiler):

exec sp_executesql N'set nocount on insert into [Business] ([Name], [Count]) values (@test_name, @test_count); select
scope_identity()',N'@test_count int,@test_name nvarchar(4000)',@test_count=0,@test_name=N'test'

` class Program
{
static void Main(string[] args)
{
Dapper.FluentMap.FluentMapper.Initialize(config =>
{
config.AddMap(new TestMap());
config.ForDommel();
});

      var conn = new SqlConnection("XXXXXX");

      var a1 = conn.SelectAsync<Test>(test => test.test_name.Contains("*test*")).Result;

      Console.WriteLine(a1.Dump());

      var a2 = conn.InsertAsync<Test>(new Test { test_id = "X", test_name = "test", test_count = 0 }).Result;
      Console.WriteLine(a2);
  }

}

public class Test
{
public string test_id { get; set; }
public string test_name { get; set; }
public int test_count { get; set; }

}

public class TestMap : DommelEntityMap
{
public TestMap()
{
ToTable("Business");

      Map(p => p.test_id).ToColumn("Id", caseSensitive: true).IsKey()
          .SetGeneratedOption(DatabaseGeneratedOption.None);

      Map(p => p.test_name).ToColumn("Name", caseSensitive: true);
      Map(p => p.test_count).ToColumn("Count", caseSensitive: true);
  }

}`

@denovellis
Copy link
Author

I would like to provide some additional information regarding the issue I reported earlier with DatabaseGeneratedOption.None. I've noticed an interesting behavior that might help in diagnosing the problem:

When I use the source code directly from the repositories of Dommel and FluentMap.Dommel, everything works as expected, and the system correctly uses the provided value for insertion without attempting to auto-increment.

However, when I switch to using the NuGet packages of these libraries, even though the versions are identical to those in the source code I initially tested with, the problem occurs where it tries to insert an auto-increment value instead.

This behavior suggests that there might be a discrepancy between the packaged versions on NuGet and the latest source code in the repositories, despite them having identical version numbers.

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

No branches or pull requests

1 participant