Connection Strings for Entity Framework

后端 未结 6 1797
挽巷
挽巷 2020-12-08 04:59

I want to share same Database information across multiple entities in Silverlight.. but I want the connection string to be named xyz and have everyone access that connection

6条回答
  •  鱼传尺愫
    2020-12-08 05:36

    Instead of using config files you can use a configuration database with a scoped systemConfig table and add all your settings there.

    CREATE TABLE [dbo].[SystemConfig]  
        (  
          [Id] [int] IDENTITY(1, 1)  
                     NOT NULL ,  
          [AppName] [varchar](128) NULL ,  
          [ScopeName] [varchar](128) NOT NULL ,  
          [Key] [varchar](256) NOT NULL ,  
          [Value] [varchar](MAX) NOT NULL ,  
          CONSTRAINT [PK_SystemConfig_ID] PRIMARY KEY NONCLUSTERED ( [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  
    
    SET ANSI_PADDING OFF  
    GO  
    
    ALTER TABLE [dbo].[SystemConfig] ADD  CONSTRAINT [DF_SystemConfig_ScopeName]  DEFAULT ('SystemConfig') FOR [ScopeName]  
    GO 
    

    With such configuration table you can create rows like such: enter image description here

    Then from your your application dal(s) wrapping EF you can easily retrieve the scoped configuration.
    If you are not using dal(s) and working in the wire directly with EF, you can make an Entity from the SystemConfig table and use the value depending on the application you are on.

提交回复
热议问题