Click here to Skip to main content
14,367,549 members
   

C#

 
AnswerRe: is any threat (as in sql injection) possible in building a 'RowFilter for a 'DataView Pin
Bernhard Hiller20-Oct-19 23:35
memberBernhard Hiller20-Oct-19 23:35 
GeneralRe: is any threat (as in sql injection) possible in building a 'RowFilter for a 'DataView Pin
BillWoodruff21-Oct-19 2:01
mveBillWoodruff21-Oct-19 2:01 
QuestionCan I convert EventArgs type to PaintEventArgs type ? Pin
Member 245846717-Oct-19 18:42
memberMember 245846717-Oct-19 18:42 
AnswerRe: Can I convert EventArgs type to PaintEventArgs type ? Pin
OriginalGriff17-Oct-19 21:09
protectorOriginalGriff17-Oct-19 21:09 
GeneralRe: Can I convert EventArgs type to PaintEventArgs type ? Pin
Member 245846717-Oct-19 23:14
memberMember 245846717-Oct-19 23:14 
GeneralRe: Can I convert EventArgs type to PaintEventArgs type ? Pin
OriginalGriff17-Oct-19 23:36
protectorOriginalGriff17-Oct-19 23:36 
GeneralRe: Can I convert EventArgs type to PaintEventArgs type ? Pin
Member 245846721-Oct-19 18:03
memberMember 245846721-Oct-19 18:03 
QuestionUpdating a List record within a record with c# and Linq, looking for something cleaner than add and remove Pin
jkirkerx17-Oct-19 13:50
professionaljkirkerx17-Oct-19 13: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 17:09
professionalLuc Pattyn17-Oct-19 17: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 7:27
professionaljkirkerx18-Oct-19 7: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 2:44
mveRichard Deeming18-Oct-19 2: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 3:02
mveRichard Deeming18-Oct-19 3: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 7:41
professionaljkirkerx18-Oct-19 7:41 
AnswerI don't get this with IndexOf not finding the record Pin
jkirkerx18-Oct-19 9:24
professionaljkirkerx18-Oct-19 9:24 
SuggestionNeed help wind form code Pin
AlexJo198516-Oct-19 23:11
memberAlexJo198516-Oct-19 23:11 
GeneralRe: Need help wind form code Pin
lw@zi 17-Oct-19 0:17
professional lw@zi 17-Oct-19 0:17 
GeneralRe: Need help wind form code Pin
Luc Pattyn17-Oct-19 16:41
professionalLuc Pattyn17-Oct-19 16:41 
AnswerRe: Need help wind form code Pin
Richard Deeming18-Oct-19 2:32
mveRichard Deeming18-Oct-19 2:32 
GeneralRe: Need help wind form code Pin
Luc Pattyn18-Oct-19 2:44
professionalLuc Pattyn18-Oct-19 2:44 
GeneralRe: Need help wind form code Pin
Richard Deeming18-Oct-19 4:03
mveRichard Deeming18-Oct-19 4:03 
GeneralRe: Need help wind form code Pin
Luc Pattyn18-Oct-19 4:26
professionalLuc Pattyn18-Oct-19 4:26 
GeneralRe: Need help wind form code Pin
#realJSOP17-Oct-19 3:01
mve#realJSOP17-Oct-19 3:01 
QuestionExistance pointers in c# Pin
Member 774487115-Oct-19 23:38
memberMember 774487115-Oct-19 23:38 
AnswerRe: Existance pointers in c# Pin
OriginalGriff15-Oct-19 23:40
protectorOriginalGriff15-Oct-19 23:40 
AnswerRe: Existance pointers in c# Pin
F-ES Sitecore15-Oct-19 23:47
mveF-ES Sitecore15-Oct-19 23: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.