Linq Using Null FK

Visual Studio .Net

    Next

  • 1. code profiling c++ code in visual studio .net 2003
    Hi folks, does anyone know how I can profile c++ code from within Visual studio .net 2003 Enterprise edition ? I looked at the MSDN help which says I need to go to the build menu, then settings, & then Project settings, then link tab -to turn profiling -However I don't see "settings" at all under the build menu ? Any help will be appreciated.
  • 2. IDE problems with copied files-intellesense stops working
    I am having off problems with a project copied over from another system and I think it was originally written in VS2002 and I've upgraded to VS2003. What happens in this, in the code editor when I start a new session everything works as usual, smart indenting works and so does intellesense. After working for awhile in the file indenting stops working. I can make it work by tabbing to another file and then back to the origianl or compiling. Finally not to long after this intellesense stops working, the IDE doesn't seem to recognize the new line. Also errors fixed are not cleared in the IDE, they still have the red line under the problem line. Again tabbing off and on the file resets it but new lines are not recognized. Loading a different project and then reloading the original resets everything and things will work again for 5 minutes or so. Things I've tried: 1) going to tools options and reseting tabs doesn't work 2) finally ran vs2003 setup and let it do a repair which takes a loooong time. It did nothing. 3) rebuilt solution: no effect It seems to be a corrupted file but this is a big project with a lot of files, anyone have any suggestions? I'm using vb.net and this is a db app using sql server. Its driving me to distraction and maybe farther. Thanks Bryan
  • 3. Refactoring Add-In
    Hi I'm looking to purchase a C# Refactoring add-in for VS.NET. Which is the best and most highly respected? Are there any magazine reviews and comparisons I could look at? Thanks Ben
  • 4. Visual Studio.NET 2005 references folder
    Does anyone know why the references folder shows in my Solution Explorer for one class library project, but not another. I cannot tell why it is not showing in one of my projects, but is showing in another one.
  • 5. Visual Studio .NET 2003 IDE freezes my computer while editing text
    Starting yesterday Visual Studio started freezing on me while using the editor. This causes the entire computer to lock up (mouse won't move, Ctrl-Alt-Delete doesn't work), forcing a reboot. I must have rebooted about 15 times yesterday and three times this morning while editing just a few lines of code. In fact, I figured out that if I just move the mouse over certain key words, even just the IntelliSense will freeze the computer. The computer works fine otherwise. This is a very small application so far (my first .NET app after many years of doing ASP work), and I'm pretty much dead in the water until I can get this resolved, or I may need to try using another editor. This first occurred while working in the following section of code: FileInfo fileInfo = new FileInfo(fullFileName); if (fileInfo.Length > maxErrorLogSize) { if (File.Exists(backupFileName)) { File.Delete(backupFileName); } // Warning!! Editing the following line in Visual Studio may cause you computer to freeze!!: fileInfo.MoveTo(backupFileName); } Even moving the mouse over the fileInfo.MoveTo line, causing the IntelliSense to kick in, causes a freeze. Can anyone help me? Thanks, Craig Randall Deloitte & Touche

Linq Using Null FK

Postby VmFjY2Fubw » Thu, 25 Sep 2008 08:31:01 GMT

I have an issue with Linq to SQL using a Null FK.  Here is the situation.

Two Tables:
TableA
  PKColumn UniqueIdentifier
  <Other Columns>

TableB
  PKColumn int
  FKColumn UnqiueIdentifer --This is a FK to table A PKColumn.

I create all of this in my Linq To SQL designer and then when I try to call
  dataContext.TableB.InsertAllOnSubmit<TableB>(ListOfTableBs);
  dataContext.SubmitChanges();
on objects that have the FKColumn set to null I get the following exception:
  Specified cast is not valid.

I have checked and double checked that my values to allow nulls are all 
correct (the FKColumn is set to allow nulls in both the DB and the designer.)

I have also run straight SQL and Sprocs to do the insert of the data and 
that works too.

I did try to override the Insert portion of my TableB object in the Linq to 
SQL Designer to use a working sproc but I still get the same exception.

Any ideas or fixes would be greatly appreciated.

Vaccano

RE: Linq Using Null FK

Postby hongyes » Thu, 25 Sep 2008 21:05:38 GMT

Hi Vaccano

For all LINQ related issues, I would suggest posting in the newsgroup below:

microsoft.public.dotnet.framework.adonet

The reason why we recommended posting appropriately is you will get the 
most qualified pool of respondents, and other partners who the newsgroups 
regularly can either share their knowledge or learn from your interaction 
with us. Thank you for your understanding.

Have a nice day!

Regards,
Hongye Sun ( XXXX@XXXXX.COM , 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: 
 XXXX@XXXXX.COM .
 
==================================================
Get notification to my posts through email? Please refer to 
 http://www.**--****.com/ #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://www.**--****.com/ 
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


Similar Threads:

1.Linq Using Null FK

I have an issue with Linq to SQL using a Null FK. Here is the situation.

Two Tables:
TableA
PKColumn UniqueIdentifier
<Other Columns>

TableB
PKColumn int
FKColumn UnqiueIdentifer (can be Null) --This is a FK to table A PKColumn.

I create all of this in my Linq To SQL designer (using normal drag and drop 
methods) and then when I try to call:

  dataContext.TableB.InsertAllOnSubmit<TableB>(ListOfTableBs);
  dataContext.SubmitChanges();

on objects that have the FKColumn set to null I get the following exception:
  Specified cast is not valid.

I have checked and double checked that my values that allow nulls are all
correct (the FKColumn is set to allow nulls in both the DB and the designer.)

Note that the insert works fine when the FKColumn value is a valid guid.

I have also run straight SQL and Sprocs to do the insert of the data and
that works too (just to ensure that my data schema was correct.)

I have tried to override the Insert portion of my TableB object in the Linq to
SQL Designer to use a working sproc but I still get the same exception.

The lack of any real info (from the debugger) on what has gone wrong makes 
this error even more frustrating.  (The call stack says nothing useful.)

Any ideas or fixes would be greatly appreciated.

Vaccano

2.Can't change FK value in object in LINQ?

Using LINQ, I'm trying to re-assign a foreign key Id in an object:

newlotpen = _LotPenClass.GetLotPen(NewPenId, NewLotId);
_Animal.LotPenId = newlotpen.LotPenId;
_AnimalClass.UpdateAnimal(_Animal, ApplicationShell.LoginID);


But, I hit an error because the generated data classes designer has this 
code:

if (this._LotPen.HasLoadedOrAssignedValue)
{
    throw new 
System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}


Someone suggested I change the code to assign the object, not just the Id:

newlotpen = _LotPenClass.GetLotPen(NewPenId, NewLotId);
_Animal.LotPen = newlotpen
_AnimalClass.UpdateAnimal(_Animal, ApplicationShell.LoginID);


I got past the first error, but now have an error in the MasterDataClass:

System.NotSupportedException was unhandled
Message="An attempt has been made to Attach or Add an entity that is not 
new, perhaps having been loaded from another DataContext.  This is not 
supported."


Does anyone know what's going on and how to resolve this?

Thanks very much for any help,
Ron

3.LINQ to SQL: Maintain FK-constraints

4.FK error when trying to update nullable FK field through ADO.N

Wow, you must be psychic!  How did you know?

Anyway, thanks very much.  Yes, indeed, I was sending 0 instead of NULL.  I 
was originally doing this and attempting to change zeros into NULLs, but I 
thought I removed that!  

5.FK error when trying to update nullable FK field through ADO.NET

Preamble:

Users table:
UserID int, PK, not null
...
CultureID int, FK, null

Cultures table:
CultureID int, OK, not null
...

When updating the DB directly, I can set the CultureID column to NULL in an 
SQL update:
e.g.  UPDATE Users SET CultureID=NULL WHERE UserID=11

However, when I try to update using a strongly typed dataset over 
webservices, I get this error:

The UPDATE statement conflicted with the FOREIGN KEY constraint 
"FK_Users_Cultures". The conflict occurred in database "CentralV1_2Dev", 
table "dbo.Cultures", column 'CultureID'.

Looking at the DataSet in the VS designer, the CultureID of the Users table 
has the following properties:
AllowDBNull: True
DefaultValue: <DBNULL>
NullValue: (Null)
ReadOnly: False
Unique: False


Can anyone tell me why I'm getting this error and/or have any suggestions on 
how I can get around it?

6. Problem with NULL values and FK constraints

7. Linq weirdness (improperly trying Column = Null instead of Column IS NULL)

8. populate dataset fk value using xmlschema xsd



Return to Visual Studio .Net

 

Who is online

Users browsing this forum: No registered users and 81 guest