none
Extensibility Methods missing RRS feed

  • Question

  • Hi. I am using LINQ To SQL, but the partial methods (OnCreated, OnLoaded, OnValidate, etc.) don't get generated. What could be the cause of this? Thanks.
    Friday, June 12, 2009 8:43 AM

Answers

All replies

  • Are you looking inside the .designer.cs file? They're declared within the regions "Extensibility Method Definitions"

    Joe

    Write LINQ queries interactively - www.linqpad.net
    Friday, June 12, 2009 2:13 PM
    Answerer
  • Yes, there is where I am looking. No partial methods, and no implementation of INotifyPropertyChanging and INotifyPropertyChanged either.
    Friday, June 12, 2009 2:19 PM
  • Probably your table does not have primary keys and LINQ To SQL does not treat it as an entity
    Friday, June 12, 2009 3:17 PM
  • No, they do not. They are kind of legacy databases, and I cannot modify them. So there is no other way I can make this work?
    Monday, June 15, 2009 7:06 AM
  • There is no other way except modifying either XML or the Designer.cs file.

    ID is necessary for correct update queries generation and for the LINQ to SQL partial methods.

    Monday, June 15, 2009 12:24 PM
  • Hi, I had a similar problem and wanted to post the answer I found. I created a solution with a Web App Project and a Class Library Project. I added a .dbml file to the Class Library Project (using LINQ to SQL Classes template) and imported all entities from a local DB. I saved the dbml changes, did a Rebuild All and added a reference to this project from the WebApp. 

    When I tried to use the generated code, I couldn't seem to find the methods InsertOnSubmit(), SubmitChanges(), etc that were supposed to be available on the entities and datacontext classes respectively. I could create an instance of any entity or the data context and set their properties.. but these methods were not there. My DB entities had a primary key set as adviced above in this post. 

    The solution was to add a reference on the WebApp project pointing to System.Data.Linq. It can seem obvious now, but I never got any compile errors indicating that the reference was missing until I decided to invoke the methods either ways to see what happened..
    • Edited by capsicums Tuesday, July 7, 2009 2:51 PM
    Tuesday, July 7, 2009 2:49 PM
  • You don't need to modify the database itself but LINQ to SQL will need to know what property or combination of properties uniquely identifies each row so that it can perform updates.  These properties must also not change.  

    If you have such properties then set them to "Primary Key" in the LINQ to SQL designer. This will not modify your database schema but will mean that LINQ to SQL can update rows within the table.

    [)amien
    Wednesday, July 8, 2009 4:55 AM
    Moderator