How can I update a SQL string with a LINQ to SQL identifier?
Given this schema:
Fruits
- FruitID INT PK
- FruitName NVARCHAR(30)
- FruitStatusID INT NULL FK: Statuses
Statuses
- StatusID INT PK
- StatusName NVARCHAR(30)
If I have FruitID
(just an int, not a Fruit object) in my hand, how do I update FruitName
and null out FruitStatusID
without first loading the Fruit object from the database?
Note: this solution got me pretty far, but I can't figure out how to zero out the FK column.
Answers in C # or VB, thanks!
+1
a source to share
1 answer
This works, but seems overly complicated:
''//initialize the values I'm going to null out to something
Dim Tag As Data_Tag = New Data_Tag() With {
.Data_Tag_ID = DataTagID,
.Last_Error_DateTime = New DateTime(),
.Last_Error_Message = "",
.Last_Error_Severity_Type_ID = -1 }
''//start change tracking
DB.Data_Tags.Attach(Tag)
''//record changes to these properties (must be initialized above)
Tag.Last_Error_DateTime = Nothing
Tag.Last_Error_Message = Nothing
Tag.Last_Error_Severity_Type_ID = Nothing
DB.SubmitChanges()
Of course the best way!
(note: the syntax comment syntax is for highliger code only - it doesn't like VB style comments)
0
a source to share