|
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; }
[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; }
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?
|
|
|
|
|
You are adding a new record to list2 with the value null , not updating the existing one.
|
|
|
|
|
I use BulkUpdate but I need to have a list of modified entities first. My problem is in the modification part. I did not provide the BulkUpdate part because I don't have any problem with it. Setting a null value to the EqInfo does not nullify the record.
modified 1-Aug-22 4:19am.
|
|
|
|
|
Sorry, I do not understand what that has to do with your question.
|
|
|
|
|
I want to remove any value in EqInfo(FOREIGN KEY). So, I tried to set it to null. But this method does not remove the record from table.
|
|
|
|
|
Yeah. Setting a FK to null is just setting a value. It will never remove a record from a table. You're just breaking a link between two records.
|
|
|
|
|
If you want to save your changes to your database, you need to call SaveChanges before you Dispose of your context.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I wouldn't "null" a relation in one case and not another. I'd create one "default" ("blank") EqInfo record to be used in those cases when Equipemnt "has none". The "reserved" InfoId could be "0" or "1"; so you use that for filtering the existence of an "actual" EqInfo's.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Hi All,
need to right a test case for webapi which is used to upload a excel sheet. currently to get file into webpai using code like HttpFileCollection file = HttpContext.Current.Request.Files;
Now to write test case for the webapi(with Moq), need to mock HttpContext.Current.Request.Files, this should have data as same as uploading excel file (even its ok to read from share location).
Please suggest the code sample or any working code.
Thanks in Advance.
|
|
|
|
|
|
Thanks for the reply, but this article not suitable for requirements.
while uploading a excel sheet, in webapi assigning this file to HttpFileCollection = HttpContext.Current.Request.Files, now need to mock HttpContext.Current.Request.Files which is having same excel file data to continue the code testing.
|
|
|
|
|
Not sure if this is the correct group for this question but I am working with C#.
I'm migrating from VS2005 to VS2022 and having problem with ControlDesigner in my Control. It seems that the ControlDesigner is not functioning. I'm not too familiar with ControlDesigner programming so after working on this for a while I decided to start from scratch. I found an example in Microsoft Help Viewer for ControlDesigner. I copied and pasted the example code into a project UserControl1 and it too does not seem to function. When moving the mouse over the control the outline does not highlight and also the OutlineColor property is not shown in the Properties window.
Can someone help? Below is the sample code from Help Viewer. The only difference the test control is called UserControl1
Thank you.
using System.ComponentModel;
namespace TestApp
{
public class ExampleControlDesigner : System.Windows.Forms.Design.ControlDesigner
{
private bool mouseover = false;
private Color lineColor = Color.White;
public Color OutlineColor
{
get
{
return lineColor;
}
set
{
lineColor = value;
}
}
public ExampleControlDesigner()
{
}
protected override void OnMouseEnter()
{
this.mouseover = true;
this.Control.Refresh();
}
protected override void OnMouseLeave()
{
this.mouseover = false;
this.Control.Refresh();
}
protected override void OnPaintAdornments(System.Windows.Forms.PaintEventArgs pe)
{
if (this.mouseover)
{
pe.Graphics.DrawRectangle(
new Pen(new SolidBrush(this.lineColor), 6),
0,
0,
this.Control.Size.Width,
this.Control.Size.Height);
}
}
protected override void PreFilterProperties(System.Collections.IDictionary properties)
{
PropertyDescriptor pd = TypeDescriptor.CreateProperty(
typeof(ExampleControlDesigner),
"OutlineColor",
typeof(System.Drawing.Color),
new Attribute[] { new DesignOnlyAttribute(true) });
properties.Add("OutlineColor", pd);
}
}
[DesignerAttribute(typeof(ExampleControlDesigner))]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
}
}
modified 30-Jul-22 7:42am.
|
|
|
|
|
Here's the same code; only more complete, it seems.
ControlDesigner Class (System.Windows.Forms.Design) | Microsoft Docs
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Yes this is the example where a copied the test code from. I tried this example 'as is' but it did not work.
The code in my question is the same; It just uses a UserControl1 that I created in my test project while debugging.
I did not include the UserControl1.Designer.cs code which includes the other code.
Thank you
|
|
|
|
|
It's not the same; it does not have / or you removed the disposing code.
Or did you think it just wasn't important so it's: "as is"?
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I'm sorry for the confusion. There are 2 files to a UserControl when created from the application:
In this case
UserControl1.cs
UserControl1.Designer.cs
The latter file contains the standard Dispose() code which I did not supply since it's just standard code.
For arguments sake, I started with the code you referenced 'as is'.. That means I copied and pasted the whole sample into a project file, built it, and tried it by loading it into a from from the toolbox; it did not function as described...
1. When the mouse moves into the control, the control does not show the highlight the border as the MouseEnter() method should do.
2. The property that is added in the designer "OutlineColor" does not show in the grid properties.
I've managed to get the debugger to work in DesignMode and set a break points in the MouseEnter() method and the OutLineColor.Set property and the OnPaintAdornments() method. None of the break points are hit when the control is loaded into the form.
thanks
|
|
|
|
|
can anybody guide me
how to save Image or Bitmap to svg file
thanks
|
|
|
|
|
|
You can't: one uses pixels (bitmap); the other uses vector graphics (xml).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
is Image a file format for saving textures? I might have heard of the "img" as file format but I`m not absolutely confident.
|
|
|
|
|
I Knew if I asked the question I would get it to work. I tried a different nuget package,
specifically System.Data.SQLite and now it works. Sorry for the bogus post.
I've just upgraded to VS2022 from VS2005 so I am sort of lost. I've tried several methods from
suggestions on the internet and still have not been able to add a reference to sqlite in my
test project. When I try to manually add the sqlite3.dll I get a message saying the dll is immutable.
Articles on the internet seem to suggest you can use it but I can't find a way to add a reference.
Can someony help?
Thanks
-- modified 28-Jul-22 20:11pm.
|
|
|
|
|
mo1492 wrote: I Knew if I asked the question I would get it to work.
That's the way if goes, sometimes - it's known as Rubber Duck Debugging[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi,
How do I set the voice in Text to Speech in C#?
I have a toolStripMenu that I load the voices into. Then when one is chosen, I want it to use that voice. Haven't been able to figure set the voice to the chosen name.
Thanks.
private void Get_Voices()
{
ISpeechObjectTokens voices = objSpeech.GetVoices("", "");
foreach (ISpeechObjectToken v in voices)
{
ts_Menu = new ToolStripMenuItem();
v_name = v.GetDescription(0);
ts_Menu.Text = v_name;
ts_Menu.CheckOnClick = true;
voicesToolStripMenu.DropDownItems.Add(ts_Menu);
ts_Menu.Click += voice_Menu_Click;
}
}
private void voice_Menu_Click(object sender, EventArgs e)
{
ToolStripMenuItem item = sender as ToolStripMenuItem;
foreach (ToolStripMenuItem tempItemp in voicesToolStripMenu.DropDownItems)
{
if (tempItemp == item)
{
tempItemp.Checked = true;
}
else
{
tempItemp.Checked = false;
}
}
choosen_voice = sender.ToString();
}
private void Speak(string txt)
{
SpVoice objSpeech = new SpVoice();
objSpeech.Speak(txt, SpeechVoiceSpeakFlags.SVSFlagsAsync);
objSpeech.WaitUntilDone(Timeout.Infinite);
}
|
|
|
|
|
|