Possibility to insert value from another model
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
Hi, is it possible to put value from another model.
For example I have a model:
public class ShoppingCartItem
{
public string ProductDescription { get; set; }
public decimal Amount { get; set; }
public string Currency { get; set; }
public int ProductCatalogId { get; set; }
public string ProductName { get; set; }
}
But I need to insert it by the following SQL query
@"insert ShoppingCartItems (ShoppingCartId, ProductCatalogId, ProductName, ProductDescription, Amount, Currency)
values ((SELECT id from ShoppingCart WHERE UserId = @UserId), @ProductCatalogId, @ProductName,@ProductDescription, @Amount, @Currency)";
Right now I do next thing
var objects = items.Select(x => new
{
**UserId = shoppingCart.UserId,**
x.ProductCatalogId,
x.ProductName,
x.ProductDescription,
x.Amount,
x.Currency
});
But I want to avoid creating new Items. It it possible to put UserId somehow?
Thank you in advance!
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 by reviewing the shown ShoppingCartItems INSERT and the anonymous projection, then inspect Dapper's parameter-binding behavior for values taken from another model. Done would mean establishing whether the requested binding is supported and documenting or implementing a clear approach without creating new item objects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100