Click here to Skip to main content
15,894,955 members
Home / Discussions / C#
   

C#

 
AnswerRe: is any threat (as in sql injection) possible in building a 'RowFilter for a 'DataView Pin
Bernhard Hiller20-Oct-19 22:35
Bernhard Hiller20-Oct-19 22:35 
GeneralRe: is any threat (as in sql injection) possible in building a 'RowFilter for a 'DataView Pin
BillWoodruff21-Oct-19 1:01
professionalBillWoodruff21-Oct-19 1:01 
QuestionCan I convert EventArgs type to PaintEventArgs type ? Pin
Member 245846717-Oct-19 17:42
Member 245846717-Oct-19 17:42 
AnswerRe: Can I convert EventArgs type to PaintEventArgs type ? Pin
OriginalGriff17-Oct-19 20:09
mveOriginalGriff17-Oct-19 20:09 
GeneralRe: Can I convert EventArgs type to PaintEventArgs type ? Pin
Member 245846717-Oct-19 22:14
Member 245846717-Oct-19 22:14 
GeneralRe: Can I convert EventArgs type to PaintEventArgs type ? Pin
OriginalGriff17-Oct-19 22:36
mveOriginalGriff17-Oct-19 22:36 
GeneralRe: Can I convert EventArgs type to PaintEventArgs type ? Pin
Member 245846721-Oct-19 17:03
Member 245846721-Oct-19 17:03 
QuestionUpdating a List record within a record with c# and Linq, looking for something cleaner than add and remove Pin
jkirkerx17-Oct-19 12:50
professionaljkirkerx17-Oct-19 12:50 
So this is really a MongoDb document class for a category, that has subCategories.
Below is an example of how the data is structured. For some reason, I'm drawing a blank on how to do this, or I've never really had a need to do it.

I want to update 1 sub category using Linq, so I can just write the whole category document using MongoDb as a ReplaceOneAsync(). But I just can't figure out how. This is in a .Net Core Controller.
{
  "_id" : "5d9f97eb29d7b329209b13cb",
  "Name" : "Solid State Drives",
  "Description": "Great Drive",
  "SubCategories" : [ 
  {
    "_id" : "5da8a1d7afb5d4084c80c9a4",
    "Name" : "NVMe",
    "Description" : "Fast Drive"
  },
  {
    "_id" : "5da8a1d7afb5d4084c80c9a4",
    "Name" : "2.5\" Form Factor",
    "Description" : "Small Drive"
  }
}
I'm thinking this, but VS didn't like the left side.
var cR = GetCategory(cid);
cR.SubCategories.FirstOrDefault(sc => sc.Id == subCategory.Id) = subCategory;
UpdateCategory(cid, cR);
I know I can do this, but I would like to preserve the original order.
cR.SubCategories.Remove(subCategory);
cR.SubCategories.Add(subCategory);
Or this
var idx = -1;
foreach (var sc in cR.SubCategories)
{
  idx++;
  if (sc.Id.Equals(subCategory.Id))
  {
    cR.SubCategories[idx] = subCategory;
  }
}

I'm just looking for clean 1 liner to do this with if it exist.
If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: Updating a List record within a record with c# and Linq, looking for something cleaner than add and remove Pin
Luc Pattyn17-Oct-19 16:09
sitebuilderLuc Pattyn17-Oct-19 16:09 
GeneralRe: Updating a List record within a record with c# and Linq, looking for something cleaner than add and remove Pin
jkirkerx18-Oct-19 6:27
professionaljkirkerx18-Oct-19 6:27 
AnswerRe: Updating a List record within a record with c# and Linq, looking for something cleaner than add and remove Pin
Richard Deeming18-Oct-19 1:44
mveRichard Deeming18-Oct-19 1:44 
AnswerRe: Updating a List record within a record with c# and Linq, looking for something cleaner than add and remove Pin
Richard Deeming18-Oct-19 2:02
mveRichard Deeming18-Oct-19 2:02 
GeneralRe: Updating a List record within a record with c# and Linq, looking for something cleaner than add and remove Pin
jkirkerx18-Oct-19 6:41
professionaljkirkerx18-Oct-19 6:41 
AnswerI don't get this with IndexOf not finding the record Pin
jkirkerx18-Oct-19 8:24
professionaljkirkerx18-Oct-19 8:24 
SuggestionNeed help wind form code Pin
AlexJo198516-Oct-19 22:11
AlexJo198516-Oct-19 22:11 
GeneralRe: Need help wind form code Pin
dan!sh 16-Oct-19 23:17
professional dan!sh 16-Oct-19 23:17 
GeneralRe: Need help wind form code Pin
Luc Pattyn17-Oct-19 15:41
sitebuilderLuc Pattyn17-Oct-19 15:41 
AnswerRe: Need help wind form code Pin
Richard Deeming18-Oct-19 1:32
mveRichard Deeming18-Oct-19 1:32 
GeneralRe: Need help wind form code Pin
Luc Pattyn18-Oct-19 1:44
sitebuilderLuc Pattyn18-Oct-19 1:44 
GeneralRe: Need help wind form code Pin
Richard Deeming18-Oct-19 3:03
mveRichard Deeming18-Oct-19 3:03 
GeneralRe: Need help wind form code Pin
Luc Pattyn18-Oct-19 3:26
sitebuilderLuc Pattyn18-Oct-19 3:26 
GeneralRe: Need help wind form code Pin
#realJSOP17-Oct-19 2:01
mve#realJSOP17-Oct-19 2:01 
QuestionExistance pointers in c# Pin
Member 774487115-Oct-19 22:38
Member 774487115-Oct-19 22:38 
AnswerRe: Existance pointers in c# Pin
OriginalGriff15-Oct-19 22:40
mveOriginalGriff15-Oct-19 22:40 
AnswerRe: Existance pointers in c# Pin
F-ES Sitecore15-Oct-19 22:47
professionalF-ES Sitecore15-Oct-19 22:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.