Hello Vaccano,
Thanks for using Microsoft Newsgroup Support Service, my name is Ji Zhou
[MSFT] and I will be working on this issue with you. I try to reproduce
your issue on my side, but with no luck. The following is what I have done.
If my steps has any difference from yours, please feel free to let me know.
1.I created a test database TestDB using SQL Server 2005 which included the
TableA and TableB,
2.The TableA and TableB's schemas were as follows,
TableA:
-----------------------------------------------------
USE [TestDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TableA](
[PKColumn] [uniqueidentifier] NOT NULL,
[TestColumn] [int] NULL,
CONSTRAINT [PK_TableA] PRIMARY KEY CLUSTERED
(
[PKColumn] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
-----------------------------------------------------
TableB:
-----------------------------------------------------
USE [TestDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TableB](
[PKColumn] [int] NOT NULL,
[FKColumn] [uniqueidentifier] NULL,
CONSTRAINT [PK_TableB] PRIMARY KEY CLUSTERED
(
[PKColumn] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TableB] WITH CHECK ADD CONSTRAINT [FK_TableB_TableA]
FOREIGN KEY([FKColumn])
REFERENCES [dbo].[TableA] ([PKColumn])
GO
ALTER TABLE [dbo].[TableB] CHECK CONSTRAINT [FK_TableB_TableA]
-----------------------------------------------------
3.Put some dump data into these tables.
4.In Visual Studio 2008, I created a Windows Form Application project. In
the project, I created LINQ to SQL Classes.
5.Connected the TestDB in the Server Explorer and dragged both the TableA
and TableB onto the designer's surface.
6.Afterwards, I used the following codes to insert rows into the TableB and
updated back to the data base, but I never encountered the exception
"Specified cast is not valid". It worked fine.
private void button1_Click(object sender, EventArgs e)
{
DataClassesDataContext dataContext = new DataClassesDataContext();
List<TableB> ListOfTableBs = new List<TableB>();
TableB tb1 = new TableB();
tb1.PKColumn = 11;
tb1.FKColumn = new Guid("3359F5F3-24AD-400f-845B-3EDE149061A0");
TableB tb2 = new TableB();
tb2.PKColumn = 12;
tb2.FKColumn = new Guid("30565AC2-8D2E-4b06-989A-8CE057BCAD8E");
TableB tb3 = new TableB();
tb3.PKColumn = 13;
tb3.FKColumn = null;
ListOfTableBs.Add(tb1);
ListOfTableBs.Add(tb2);
ListOfTableBs.Add(tb3);
dataContext.TableBs.InsertAllOnSubmit<TableB>(ListOfTableBs);
dataContext.SubmitChanges();
}
So, may I suggest you use the above steps in your side to see if you can
still reproduce the error? To better troubleshoot this problem, firstly I
need to reproduce it on my side. So would you like to provide the detailed
reproduce information. The sample SQL database file with pseudo data, as
well as the detailed codes are preferred. If you cannot share that, would
you mind posting the TableA and TableB's SQL statement in the step2, and
the exception's stack trace? Sorry about taking so many questions to you. I
just intend to help on this and that information is needed to narrow down
the problem. Thanks for your understanding!
If there are confidential data in these information, would you like to
share it by sending me emails? You can access me by the address
(e-mail address removed).
Have a nice day!
Best regards,
Ji Zhou (
[email protected], remove 'online.')
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.