none
LINQ to SQL Classes Visual Studio Item - Multiple Databases RRS feed

  • Question

  • Long story short, my hosting provider is limited on how large my databases can be, so I have to segment them out into separate databases.

    In one of my projects, I have a /Data/DataSources folder where I put all my dbml files.  My problem is, whenever I add a table that exists in other databases, I get a bunch of errors, mostly The Type 'X' already contains a definition for 'Y', 'A partial method may not have multiple defining declarations' and 'Type 'X' already defines a member called 'SendPropertyChanging' with the same parameter types'

     

    Any idea how to get around this?

    Tuesday, April 20, 2010 12:12 PM

Answers

  • Hello,

     

    Welcome to MSDN forums!

     

    By default, LINQ to SQL will generate entity classes with the same name of the database tables.   So if your .dbml, DataContext and all the entity classes are under the same namespace, the errors are expected.    To work around this, can you add some sub folders in the /Data/DataSources folder?    In each sub folder, we put in a .dbml.   In C# projects, the sub folder name will be added into the namespace automatically, like MyProjects.Data.DataSources.SubFolder1.   

     

    Or you can also consider using some custom methods to generate the LINQ to SQL classes instead of using VS built-in way.   LINQ to SQL T4 template is a good option, http://l2st4.codeplex.com/.   

     

    If you have any questions, please feel free to let me know.

     

    Have a great day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com

     

    BTW, I will move this thread to LINQ to SQL forum since the question is more appropriate there. 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, April 21, 2010 1:30 AM
    Moderator

All replies

  • Hello,

     

    Welcome to MSDN forums!

     

    By default, LINQ to SQL will generate entity classes with the same name of the database tables.   So if your .dbml, DataContext and all the entity classes are under the same namespace, the errors are expected.    To work around this, can you add some sub folders in the /Data/DataSources folder?    In each sub folder, we put in a .dbml.   In C# projects, the sub folder name will be added into the namespace automatically, like MyProjects.Data.DataSources.SubFolder1.   

     

    Or you can also consider using some custom methods to generate the LINQ to SQL classes instead of using VS built-in way.   LINQ to SQL T4 template is a good option, http://l2st4.codeplex.com/.   

     

    If you have any questions, please feel free to let me know.

     

    Have a great day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com

     

    BTW, I will move this thread to LINQ to SQL forum since the question is more appropriate there. 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, April 21, 2010 1:30 AM
    Moderator
  • After a decent google search, I just simply changed the namespace which didn't take that long to do.

     

    Thank you for the reply.

    Wednesday, April 21, 2010 1:11 PM
  • Glad to hear the problem is solved.  

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, April 22, 2010 8:16 AM
    Moderator