|
Since I am new to working with linq in a C# 2010 .net application, I have the following question to ask:
In some new code that I need to write, I need to insert a new row in org1 table where the identity (key) column is called org1_id. I also need to insert a row in org2 table that has org1_id column as foreign key (that is associated with org1 table.
How would you accomplish this task?
The following is what i have so far:
[^]org = new Organization();
PopulateOrganization(org);--puts data in all the appropriate columns
orgModuleDataContext.Organizations.InsertOnSubmit(org); [^]
|
|
|
|
|
It seems your question is related more to Entity Framework than Linq specifically.
This is about performance but there are examples of foreign key relationships with EF.
Entity Framework Performance[^]
No comment
|
|
|
|
|
Hi,
What is the best way to convert a point string to a point object ?
Point Pt1 = new Point(10, 20);
string strPt = Pt1.ToString();
Point Pt2 = ? (use strPt to convert back to Point object)
Thx.
|
|
|
|
|
paper67 wrote: What is the best way to convert a point string to a point object ?
Using the appropriate TypeConverter[^]
Bastard Programmer from Hell
|
|
|
|
|
First new class of the week!
|
|
|
|
|
No, they won't be covering classes or instantiation for a while yet
|
|
|
|
|
|
Interestingly, I tried that but it fails, as the ouput of Point.ToString() is not parsable by the converter.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I'm not surprised. The .ToString method shows the contents of the object, it doesn't convert it to it's string-representation. I'd expect one would have to go from object->string and vice versa over the TypeConverter .
Bastard Programmer from Hell
|
|
|
|
|
If you have control over both parts of the operation, i.e. this is for persisting some data you own to disk/network/etc, you should use the TypeConverter:
Point pt1 = new Point(10, 20);
string strPt = TypeDescriptor.GetConverter(pt1).ConvertToString(pt1);
Point pt2 = TypeDescriptor.GetConverter(typeof(Point)).ConvertFromString(strPt);
If you don't have control over the string format, you will have to write a parser. It's pretty simple (clean off the brackets, split on ',', verify two parts, aand parse both halves as int).
|
|
|
|
|
If you have control over both ends, why use strings at all?
|
|
|
|
|
As an intermediate format without having to resort to serialization
Bastard Programmer from Hell
|
|
|
|
|
|
True, that's an option too
You can store every class by simply looping it's public properties, and to store the contents as a string. (Storing both ints in a string is the same thing) That would mean that you have to pay attention to the format, and match up the encode/decode functions.
The TypeConverter is a somewhat "safer" way of converting your class, because it adheres to a fixed format for that type in a human-readable form. It's not only used for locations, but also for colors and the like. This would be my recommendation.
A third option would be serialization. That'd be a bit overkill in this particular situation, but it remains an option.
Bastard Programmer from Hell
|
|
|
|
|
Well I was just going to store the ints and ints, but yea it really depends on where the data is supposed to go..
|
|
|
|
|
Eddy Vluggen wrote: You can store every class by simply looping it's public properties, and to store the contents as a string. Just curious: you mean by using Reflection ?
And, if I may ask, why would serialization be "over-kill" in this scenario ... assuming this question is not a one-off, but has broader implications.
And, how about using Mehdi Gholam's zippy implementation of JSON on steroids here on CP ? Over-kill ?
best, Bill
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright
|
|
|
|
|
BillWoodruff wrote: Just curious: you mean by using Reflection ?
That's what it implies, and yes, I know that you don't need reflection for serialization.
BillWoodruff wrote: And, if I may ask, why would serialization be "over-kill" in this scenario ... assuming this question is not a one-off, but has broader implications.
Because the TS gave an example where he'd convert a small structure to a string and back. If he had asked how to store a class or a collection, I'd answered serialization.
BillWoodruff wrote: And, how about using Mehdi Gholam's zippy implementation of JSON on steroids here on CP ? Over-kill ?
I'm not familiar with the article, but it sounds like a viable alternative.
Bastard Programmer from Hell
|
|
|
|
|
Typically the answer to this is if you want to store something in a human readable form. Object->string conversions are often part of file I/O. (This is what I'm using similar code for.) Or, for a web app, creating a POST request body, though there it might be better to use &x=42&y=72.
|
|
|
|
|
Ah yes of course, I was thinking too much in terms of persistence
|
|
|
|
|
Hey guys,really need some serious help with my capcha code project.My caphca code variation is that it has to consist of a number pattern and the user has to input the missing number
For eg. 2,4,6__,10 (Fill in the missing code)
I already have the graphics class setup ,so just the code for randomly generating a number pattern itself.Please Help guys.I'm a beginner programer.Help much appreciated.
|
|
|
|
|
What sorts of pattern do you want?
Once you successfully answer that question (defining the pattern types that are valid) it should be trivial to write it in code.
|
|
|
|
|
Show us what code you've got and indicate what the problem is, then maybe we can help.
Otherwise, look at recaptcha[^]
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun
|
|
|
|
|
Hi Guys!
I am trying to make one simple application where i want to have info from db(Damain Z)
example:
I am in Damain X where the tool will reside,i have a bridge domain Y and a domain Z where DB resides..
any clue how to solve this senario!!!
vikas da
|
|
|
|
|
If these is no trust setup between Domain Z and Domain X, you're limited to using SQL Server accounts and SQL Authentication. The problem with this is maintaining the accounts on the SQL Server, seperate from everyones AD account.
|
|
|
|
|
Crystal report not open other system in 32bit window 7 AMD processor
and report related files............
thanks in advance.
|
|
|
|