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

Merge failed when PK column was not passed in the dataset #18

Closed
rdagumampan opened this issue Jul 16, 2018 · 1 comment
Closed

Merge failed when PK column was not passed in the dataset #18

rdagumampan opened this issue Jul 16, 2018 · 1 comment
Assignees
Labels
bug Something isn't working deployed Feature or bug is deployed at the current release

Comments

@rdagumampan
Copy link
Contributor

Merge failed when PK column was not passed in the dataset. It used to be working but have now failed after the latest fixes in Master.

Tests available in my fork https://github.com/rdagumampan/RepoDb.

Open the

[Test]
public void TestMergeInsert()
{
	//arrange
	var repository = new DbRepository<SqlConnection>(Constants.TestDatabase);

	var fixtureData = new Customer
	{
		GlobalId = Guid.NewGuid(),
		FirstName = "Juan-MERGED",
		LastName = "de la Cruz-MERGED",
		MiddleName = "Pinto-MERGED",
		Address = "San Lorenzo, Makati, Philippines 4225-MERGED",
		IsActive = true,
		Email = "juandelacruz@gmai.com-MERGED",
		LastUpdatedUtc = DateTime.UtcNow,
		LastUserId = Environment.UserName
	};

	//act
	repository.Merge(fixtureData);

	//assert
	var customer = repository.Query<Customer>(new { fixtureData.GlobalId }).FirstOrDefault();
	customer.ShouldNotBeNull();
	customer.Id.ShouldNotBe(0);
	customer.GlobalId.ShouldBe(fixtureData.GlobalId);
	customer.FirstName.ShouldBe(fixtureData.FirstName);
	customer.LastName.ShouldBe(fixtureData.LastName);
	customer.MiddleName.ShouldBe(fixtureData.MiddleName);
	customer.Address.ShouldBe(fixtureData.Address);
	customer.Email.ShouldBe(fixtureData.Email);
	customer.IsActive.ShouldBe(fixtureData.IsActive);
	customer.LastUpdatedUtc.ShouldBe(fixtureData.LastUpdatedUtc);
	customer.LastUserId.ShouldBe(fixtureData.LastUserId);
}
System.Data.SqlClient.SqlException : Must declare the scalar variable "@Id".
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)

@rdagumampan rdagumampan added the bug Something isn't working label Jul 16, 2018
@rdagumampan
Copy link
Contributor Author

Closed as As Designed.
Id must be passed when Merge is called. The internal generated SQL needs the column for identifying source and destination.

@mikependon mikependon self-assigned this Aug 4, 2018
@mikependon mikependon added the deployed Feature or bug is deployed at the current release label Aug 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working deployed Feature or bug is deployed at the current release
Projects
None yet
Development

No branches or pull requests

2 participants