none
Association exist in dbml view, but without generated code! RRS feed

  • General discussion

  • Hi all,

    I have 2 table that have a relation; i.e: A customer have some Order, when I create dbml file and drag these tables to it, I can see association in dbml viewer, but when I use one of tables in code, don't have property for this relation! I check all generated code, but don't find any generated code for this association! Note that when I drag other tables, all associations work correctly!

    Please help me for this problem!

    Thursday, December 9, 2010 6:41 AM

All replies

  • Hi AliPooneh,

     

    Welcome to MSDN forum,  and thank you for posting in MSDN Forum.

    My name is Jackie Sun and I will be working with you on this case.  So please feel free to let me know if I have misunderstood anything.

    Since I did some research,  I haven't met this situation like yours.  However,  I can give you some suggestions:

    1.       You can try to restart your Visual Studio with your files saved.

    2.       Save your files and build or rebuild your solution.

    3.       Restart your computer.

    4.       Repair your Visual Studio or reinstall it (This is the last thing you can do).

     

    I hope this will help resolve your problem. If anything is unclear, please free feel to let us know.

     

    Thank you for your understanding and support.

    I look forward to hearing from you.

     

    Best Regards,

     


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 15, 2010 2:21 AM
    Moderator
  • Hi AliPooneh,

    Could you post the database metadata for these two tables (at least the key columns); in case there is something unusual about these?

    Also you could try to manually remove and re-add the association in the O/R Designer surface to see what happens. You might, at least, get some informational message about the reason for it not working properly.

    Regards,

    John.

    Wednesday, December 15, 2010 3:38 PM
  • I have a problem similar to yours. 

     

    I generated my dbml using Sql metal and then decided to ask two more table with foreign key

    i've set the two tables and set the relationship.. in the dbml view.

     

    in the dbml view i could see the association but there are no generated code in the classes.

    could you please point out whats wrong ? cause i got one table with working association (added manually) but the other do not have a working association (also added manually) 

     

    for side notes, i've checked the database association and it has no problem.

     

    EDITED : PROBLEM SOLVED.. i need to trick visual studio to create the necessary association by adding a data.

    Friday, December 17, 2010 2:06 AM
  • Hi AliPooneh,

     

    Welcome to MSDN forum,  and thank you for posting in MSDN Forum.

    My name is Jackie Sun and I will be working with you on this case.  So please feel free to let me know if I have misunderstood anything.

    Since I did some research,   I haven't met this situation like yours.   However,  I can give you some suggestions:

    1.       You can try to restart your Visual Studio with your files saved.

    2.       Save your files and build or rebuild your solution.

    3.       Restart your computer.

    4.       Repair your Visual Studio or reinstall it (This is the last thing you can do).

     

    I hope this will help resolve your problem. If anything is unclear, please free feel to let us know.

     

    Thank you for your understanding and support.

    I look forward to hearing from you.

     

    Best Regards,

     


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Hi dear, Thanks for your help. I test all ways that you said, Restart VS, drag all my tables again, create another dbml, repair or reinstall VS, restart computer and other and other,

    Also I delete association in dbml and save it, and I create an association manually in dbml, But no generated code appears in code behind and my first entity doesn't have property of type second entity.


    Pooneh.
    Saturday, December 18, 2010 5:52 AM
  • Hi John.

    I use SQL Server management to create script for create my two tables.

    Note to it:

    CREATE TABLE [dbo].[Tbl_DarkhastTashilat](
    	[ID] [int] IDENTITY(1,1) NOT NULL,
    	[Rahgiry] [nvarchar](50) NULL,
    	[MainRahgiry] [nvarchar](50) NULL,
    	
    	--some other columns
    	
     CONSTRAINT [PK_Tbl_DarkhastTashilat] PRIMARY KEY CLUSTERED 
    (
    	[ID] 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
    
    CREATE TABLE [dbo].[Tbl_DarkhastTashilatKomitte](
    	[Id] [int] NOT NULL,
    	[DarkhastId] [int] NOT NULL,
    	[Komitte] [int] NOT NULL,
    	
    	--some other columns
    	
    ) ON [PRIMARY]
    GO
    
    /****** Object: ForeignKey [FK_Tbl_DarkhastTashilatKomitte_Tbl_DarkhastTashilat22]  Script Date: 12/18/2010 09:27:07 ******/
    ALTER TABLE [dbo].[Tbl_DarkhastTashilatKomitte] WITH CHECK ADD CONSTRAINT [FK_Tbl_DarkhastTashilatKomitte_Tbl_DarkhastTashilat22] FOREIGN KEY([DarkhastId])
    REFERENCES [dbo].[Tbl_DarkhastTashilat] ([ID])
    GO
    ALTER TABLE [dbo].[Tbl_DarkhastTashilatKomitte] CHECK CONSTRAINT [FK_Tbl_DarkhastTashilatKomitte_Tbl_DarkhastTashilat22]
    GO
    
    
    Thanks for your help.


    Pooneh.
    Saturday, December 18, 2010 6:00 AM