Click here to Skip to main content
15,510,281 members
Home / Discussions / C#
   

C#

 
AnswerRe: Facing problem when calling store procedure from c# code Pin
Richard Deeming2-Aug-22 22:21
mveRichard Deeming2-Aug-22 22:21 
GeneralRe: Facing problem when calling store procedure from c# code Pin
Mou_kol3-Aug-22 4:27
Mou_kol3-Aug-22 4:27 
GeneralRe: Facing problem when calling store procedure from c# code Pin
Victor Nijegorodov3-Aug-22 6:33
Victor Nijegorodov3-Aug-22 6:33 
QuestionRe: Facing problem when calling store procedure from c# code Pin
thatraja2-Aug-22 22:36
professionalthatraja2-Aug-22 22:36 
AnswerRe: Facing problem when calling store procedure from c# code Pin
Gerry Schmitz3-Aug-22 6:58
mveGerry Schmitz3-Aug-22 6:58 
QuestionHow to dispose Interaction.Behaviors in WPF Pin
Code4Ever2-Aug-22 6:45
Code4Ever2-Aug-22 6:45 
AnswerRe: How to dispose Interaction.Behaviors in WPF Pin
Gerry Schmitz2-Aug-22 7:21
mveGerry Schmitz2-Aug-22 7:21 
QuestionHow to set null value to a FOREIGN KEY using EF Core Pin
Code4Ever31-Jul-22 21:38
Code4Ever31-Jul-22 21:38 
I have the following model:

public class Equipment
    {
        [Key]
        public int EquipmentId { get; set; }
        [Required]
        public string EquipmentCode { get; set; }
        [Required]
        public string EquipmentTitle { get; set; }

        //Navigation Property
        [Required]
        public int CostCenterId { get; set; }
        public CostCenter CostCenter { get; set; }
        public int? InfoId { get; set; }
        [ForeignKey("InfoId")]
        public EqInfo? EqInfo { get; set; }
        public Catalogue? Catalogue { get; set; }
    }

public class EqInfo
    {
        [Key]
        public int InfoId { get; set; }
        [Required]
        public string InfoFileName { get; set; }

        //Navigation property
        public virtual List<Equipment> Equipments { get; set; }
    }


I want to update the EqInfo entity to null in a list of selected items:

foreach (var row in AssociatedObject.dataGrid.SelectedItems)
                    {
                        var _sqliteContext = new SQLiteContext();
                        var selectedRecord = _sqliteContext.Equipments.Include(x => x.EqInfo).FirstOrDefault(x => x.EquipmentId == (int)reflector2.GetValue(row, "EquipmentId"));
                        selectedRecord.EqInfo = null;
                        list2.Add(selectedRecord);
                        _sqliteContext.Dispose();
                    }


selectedRecord.EqInfo = null; not works as expected. It keeps the previous value and is not set to null.

How can I fix it?
AnswerRe: How to set null value to a FOREIGN KEY using EF Core Pin
Richard MacCutchan31-Jul-22 22:37
mveRichard MacCutchan31-Jul-22 22:37 
GeneralRe: How to set null value to a FOREIGN KEY using EF Core Pin
Code4Ever31-Jul-22 22:49
Code4Ever31-Jul-22 22:49 
GeneralRe: How to set null value to a FOREIGN KEY using EF Core Pin
Richard MacCutchan31-Jul-22 23:06
mveRichard MacCutchan31-Jul-22 23:06 
GeneralRe: How to set null value to a FOREIGN KEY using EF Core Pin
Code4Ever31-Jul-22 23:17
Code4Ever31-Jul-22 23:17 
GeneralRe: How to set null value to a FOREIGN KEY using EF Core Pin
Dave Kreskowiak1-Aug-22 5:23
mveDave Kreskowiak1-Aug-22 5:23 
AnswerRe: How to set null value to a FOREIGN KEY using EF Core Pin
Richard Deeming1-Aug-22 1:25
mveRichard Deeming1-Aug-22 1:25 
AnswerRe: How to set null value to a FOREIGN KEY using EF Core Pin
Gerry Schmitz1-Aug-22 8:02
mveGerry Schmitz1-Aug-22 8:02 
QuestionMocking HttpContext Pin
SreeRama Govind31-Jul-22 18:26
SreeRama Govind31-Jul-22 18:26 
AnswerRe: Mocking HttpContext Pin
Pete O'Hanlon2-Aug-22 0:26
mvaPete O'Hanlon2-Aug-22 0:26 
GeneralRe: Mocking HttpContext Pin
SreeRama Govind3-Aug-22 9:59
SreeRama Govind3-Aug-22 9:59 
QuestionControlDesigner issue Pin
mo149230-Jul-22 1:51
mo149230-Jul-22 1:51 
AnswerRe: ControlDesigner issue Pin
Gerry Schmitz30-Jul-22 6:04
mveGerry Schmitz30-Jul-22 6:04 
GeneralRe: ControlDesigner issue Pin
mo149230-Jul-22 8:35
mo149230-Jul-22 8:35 
GeneralRe: ControlDesigner issue Pin
Gerry Schmitz30-Jul-22 15:49
mveGerry Schmitz30-Jul-22 15:49 
GeneralRe: ControlDesigner issue Pin
mo149231-Jul-22 7:43
mo149231-Jul-22 7:43 
Questionhow to save Image or Bitmap to svg file Pin
Le@rner29-Jul-22 2:51
Le@rner29-Jul-22 2:51 
AnswerRe: how to save Image or Bitmap to svg file Pin
OriginalGriff29-Jul-22 3:19
mveOriginalGriff29-Jul-22 3:19 

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.