|
What? That can't be. A table has only one primary key.
Don't mind those people who say you're not HOT. At least you know you're COOL.
I'm not afraid of falling, I'm afraid of the sudden stop at the end of the fall! - Richard Andrew x64
|
|
|
|
|
First we need to clarify what you mean with "two primary keys". Is it a rpimary key which consists of both "RegionID" and "DistrictID"? Or did you calculate an extra value from those data and make that your primary key?
Or is it actually one foreign key and one primary key?
Or something else?
|
|
|
|
|
Thanks for your reply, yes, it's a primary key which consitsts of both RegionID and DistrictID.
|
|
|
|
|
a 'compound' primary key.
Regards,
Rob Philpott.
|
|
|
|
|
Thanks, can you provide a simple code? Thanks
public class Region
{
// what I should define here
public int RegionID {get;set;}
// then what I should define here
public int DistrictID {get;set;}
}
|
|
|
|
|
You haven't stated what database you're using or whether you are using an ORM (which it looks like you are), and if so which one.
Personally I never use ORMs, so I can't advise I'm afraid.
Regards,
Rob Philpott.
|
|
|
|
|
public class Region
{
[Key, Column(Order = 0)]
public int RegionId { get; set; }
[Key, Column(Order = 1)]
public int DistrictId { get; set; }
} That is, assuming you're using EF; you still did not specify which mapper you are using. I'd also like to recommend an artificial key, and to decorate your compound key with a unique-constraint. Having a single attribute to identify a record makes life a bit easier when having to reference a specific record.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you very much, I am runnig into an error when using Order, I have the using System.ComponentModel.DataAnnotations.Schema and System.ComponentModel.DataAnnotations, I am using VS12, can you tell me what I am missing? Thanks again.
|
|
|
|
|
What error?
It might help if you post the exception
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
System.Data.Linq.Mapping.ColumnAttribute' does not contain a definition for 'Order'
|
|
|
|
|
Like I said, I was assuming you're using the Entity Framework, but there's always MSDN[^] to help.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi all,
I use a certain command/process which i run in the command line. After it is started, it'll keep polling until i hit Ctrl-C. I use the command in multiple cmd windows (it's used for multiple directories).
Now i want to create a little C# program which is shown in the Windows toolbar where the user can create new processes of it (multiple), can manage to 'stop' (ctrl-c) a certain process, etc.
But somehow i cannot get this to work, especially the 'multiple' part. I cannot create multiple command windows with different commands, which i can manage afterwards (by ID or so).
I tried the solution of this thread: Starting cmd.exe in console application in different window.[^]
However, in that example you can only give 1 command - so the Ctrl-C cannot happen at a later stage.
Is this possible in C#? And if not, which language can do this?
Sorry for my poor english.
|
|
|
|
|
Since your application is starting the external processes, it's simple: all you have to do is keep a reference to teh Process object you used to start it, and then use SendKeys:
StartProcess("Notepad.exe");
}
private Process notePad;
private void StartProcess(string p)
{
notePad = new Process();
notePad.StartInfo.FileName = p;
notePad.Start();
}
[DllImport("User32.dll")]
static extern int SetForegroundWindow(IntPtr point);
private void butSendDataToNotepad_Click(object sender, EventArgs e)
{
IntPtr hWnd = notePad.MainWindowHandle;
SetForegroundWindow(hWnd);
SendKeys.SendWait(tbDataToSend.Text);
}
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Thank you for your reply.
I tried your suggestion with a little test. So far it worked, i was able to create 2 separate cmd.exe processes and was able to send commands to it any time i wanted. However, the windows of the cmd.exe processes where all open, and got focus if it wrote a command in it. When i tried to hide the windows with this:
this.process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
It didn't work anymore. The problem is here i think that the combination of 'SetForegroundWindow' and'SendKeys' will need an active window - it simulates user input, so it needs an active window which isn't hidden to send keys to it.
Is there some way to hide it? The user must not be able to see the cmd.exe processes, it should all just run in the background.
|
|
|
|
|
i do not anything about state machine. so anyone please briefly discuss in easy way what is state machine? in what kind of situation people think to develop or use any existing state machine. explain with example & scenario. thanks
tbhattacharjee
|
|
|
|
|
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
In this case, a simple Google would find you all the answers: it found me this straight away.
A Simple State Machine[^]
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I wouldn't bother. It's plain from earlier questions that this member doesn't bother with anything as boring as doing research.
|
|
|
|
|
<pre>
using System;
using System.IO;
using System.Collections;
namespace check
{
static class Program
{
static void Main(string[] args)
{
ulong increment = 2;
for (ulong i = 0; i < 70; i++)
{
increment += i * increment;
Console.WriteLine("{0}",increment);
}
}
}
}
|
|
|
|
|
Use
checked
Like in example bellow:
try
{
z = checked(maxIntValue + 10);
}
catch (System.OverflowException e)
{
Console.WriteLine("CHECKED and CAUGHT: " + e.ToString());
}
checked on msdn
|
|
|
|
|
Where does the "e" comes from. What does "e" mean?
|
|
|
|
|
Look at type
catch (System.OverflowException e)
{ ...
e is my variable name it is short for exception. It is not obligatory to use any name if you wanna catch OverflowException without more information.
|
|
|
|
|
See here: checked (C# Reference)[^]
Or you can enable it for the whole app:
Go to project Properties and find the Build tab.
Click "Advanced" button.
In the resulting dialog, check the “Check for arithmetic overflow/underflow” box, and press OK.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Edit your question and provide better information.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Actually, it's not even a question. Just some words.
Regards,
Rob Philpott.
|
|
|
|