DapperLib / DapperLib/Dapper.Contrib
Dapper.Contrib ArgumentException: Entity must have at least one [Key] or [ExplicitKey] property
Open
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 293
- Forks
- 109
- PR merge metrics
- No merged PRs in 30d
Description
Hi!
I'm getting exception during update
Dapper.Contrib.Extensions.SqlMapperExtensions.Update<T>(IDbConnection connection, T entityToUpdate, IDbTransaction transaction, Nullable<int> commandTimeout)
OptimoKasiarz.Data.Classes.SQL.UpdatePodatnik(string connectionString, Podatnicy pdt) in SQL.cs
con.Update(pdt);
OptimoKasiarz.Pages.Podatnik.EditModel+<OnPostAsync>d__39.MoveNext() in Edit.cshtml.cs
SQL.UpdatePodatnik(SQL.FirmaConnectionString, podatnik);
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNetCore.Mvc.RazorPages.Internal.ExecutorFactory+GenericTaskHandlerMethod+<Convert>d__4.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNetCore.Mvc.RazorPages.Internal.ExecutorFactory+GenericTaskHandlerMethod+<Execute>d__3.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker+<ExecuteHandlerMethod>d__22.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker+<ExecutePageWithPageModelAsync>d__19.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker+<InvokeInnerFilterAsync>d__15.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeNextResourceFilter>d__22.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeFilterPipelineAsync>d__17.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeAsync>d__15.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Builder.RouterMiddleware+<Invoke>d__4.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+<Invoke>d__6.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+<Invoke>d__7.MoveNext()
I put [Key] annotation to my class
public class Podatnicy
{
[Key]
public int PdT_PdTId { get; set; }
public string PdT_Nazwa { get; set; }
public string PdT_NIP { get; set; }
public string PdT_Imie { get; set; }
public string PdT_Nazwisko { get; set; }
public string PdT_Miasto { get; set; }
public string PdT_Ulica { get; set; }
public string PdT_NrDomu { get; set; }
public string PdT_NrLokalu { get; set; }
public string PdT_KodPocztowy { get; set; }
public string PdT_Wojewodztwo { get; set; }
public string PdT_NrTel { get; set; }
public string PdT_Email { get; set; }
public string PdT_Uwagi { get; set; }
public bool PdT_Aktywny { get; set; } = true;
public int? PdT_UrZId { get; set; }
}
and update function:
public static void UpdatePodatnik(string connectionString, Podatnicy pdt)
{
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
con.Update(pdt);
}
}
What am I doing wrong?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at SqlMapperExtensions.Update and trace how the [Key] attribute is detected for the Podatnicy type shown in the report. Reproduce the con.Update(pdt) call from SQL.cs, then identify why the declared key is not recognized and add a regression test covering that case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100