This is a migrated thread and some comments may be shown as answers.

Designer: Update Database from Model

2 Answers 136 Views
Design Time (Visual Designer & Tools)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Brian
Top achievements
Rank 1
Brian asked on 28 Sep 2010, 05:23 PM
I've encountered a new problem when I try to generate a new data schema script.  Here is what I do:
  • Create an empty database
  • Verify that the connection string in App.Config and the .rlinq file match and are correct.  The .rlinq strings are in rlinq|runtime|modelsettings|AppConfigConnectionString and DesignTimeConnectionString.
  • Save the .rlinq file
  • Perform a rebuild of the project (and the entire solution to make sure, sometimes rebooting and rebuilding to make double sure)
  • Verified that there are no compile warnings or errors in the project.  Not even the ones that only show up when you save the .rlinq file. I also did a Validate all on the .rlinq file design surface and it passed.
  • Open the .rlinq file so you can right click on the designer surface to get the Update Database from Model.. choice
  • See my connection string as it was put in the App.Config and .rlinq files.  One interesting thing is that in the connection: dropdown, my connection string named 'MyDBC' shows up twice, with the second instance pruning the last character from the database name (in the initial catalog portion of the connection string).  I wonder if this has something to do with it?  I've searched, and there is no such abbreviated string in my entire project.
  • Click next, leaving 'Generate and Execute Schema Definition Script'
  • Click next, get 'Project not built' dialog saying 'Please rebuild the project in order to advance to the next step'.  Also does this when I try to click Previous, by the way.
Note that this worked at recently as a week ago with the same ORM version (2010.2.804.5).  I've not installed or changed anything.  So, I suspect I've triggered something by simply editing my model over the past week.

Short of me sending you my whole project, which I would rather not, do you have any other tips for making sure the model stays healthy enough to avoid this from happening?

Also, I suspect the problem has to do with the 2 connection strings showing up in the first wizard page (which does not show up in other working projects because there is only 1).  What do I have to edit to remove the second (broken) one?  I've searched files in the project and the registry to no avail...

2 Answers, 1 is accepted

Sort by
0
Brian
Top achievements
Rank 1
answered on 28 Sep 2010, 07:26 PM
I found the problem, which was related to the fact that I changed the name of the connection string and model name.  So, I have a new design pattern I'll enforce for myself:
  • Choose a name for your model that will make sense in the code for the context.  Mine is 'MyContext' for my ORM N-Tier Domain Model Forward Development project, which is what helped me find the problem compared to my production code.
  • In App.Config, make sure your connectionString name is 'MyContext'
    <configuration>
      <connectionStrings>
        <add name="MyContext" connectionString="data source=(local)\SQL2008;initial catalog=MyORM;integrated security=True" providerName="System.Data.SqlClient" />
      </connectionStrings>
    </configuration>
  • In the MyContext.rlinq file (another good naming practice) in the rlinq|Runtime|ModelSettings you should have MyContext show up consistently for AppConfigurationPropertyName & ModelName, and 'MyORM' should match the initial catalog of the connection string and the InitialCatalog entity.  I also included some code generation default goodness with some second level caching, for the interested reader.
    <ModelSettings xmlns="">
      <AppConfigConnectionPropertyName>MyContext</AppConfigConnectionPropertyName>
      <AppConfigConnectionString>Data Source=(local)\SQL2008;Initial Catalog=MyORM;Integrated Security=True</AppConfigConnectionString>
      <DesignTimeConnectionString>Data Source=(local)\SQL2008;Initial Catalog=MyORM;Integrated Security=True</DesignTimeConnectionString>
      <InitialCatalog>MyORM</InitialCatalog>
      <SaveConnectionStringInAppConfig>true</SaveConnectionStringInAppConfig>
      <ModelNamespace>MyModel</ModelNamespace>
      <ModelName>MyContext</ModelName>
      <NamingSettings>
        <ClassRules>
          <AddPrefix />
          <AddSuffix />
          <RemovePrefix />
          <RemoveSuffix />
          <CaseMode>PascalCase</CaseMode>
          <PluralizationMode>Singularize</PluralizationMode>
          <PluralizationModeCollections>Unchanged</PluralizationModeCollections>
          <RemoveUnderscore>false</RemoveUnderscore>
          <UnderscoreAsWordDelimiter>true</UnderscoreAsWordDelimiter>
          <SchemaNameAsPrefix>false</SchemaNameAsPrefix>
        </ClassRules>
        <FieldRules>
          <AddPrefix />
          <AddSuffix />
          <RemovePrefix />
          <RemoveSuffix />
          <CaseMode>PascalCase</CaseMode>
          <PluralizationMode>Singularize</PluralizationMode>
          <PluralizationModeCollections>Pluralize</PluralizationModeCollections>
          <RemoveUnderscore>false</RemoveUnderscore>
          <UnderscoreAsWordDelimiter>true</UnderscoreAsWordDelimiter>
          <SchemaNameAsPrefix>false</SchemaNameAsPrefix>
        </FieldRules>
        <PropertyRules>
          <AddPrefix />
          <AddSuffix />
          <RemovePrefix />
          <RemoveSuffix />
          <CaseMode>PascalCase</CaseMode>
          <PluralizationMode>Singularize</PluralizationMode>
          <PluralizationModeCollections>Pluralize</PluralizationModeCollections>
          <RemoveUnderscore>false</RemoveUnderscore>
          <UnderscoreAsWordDelimiter>true</UnderscoreAsWordDelimiter>
          <SchemaNameAsPrefix>false</SchemaNameAsPrefix>
        </PropertyRules>
      </NamingSettings>
      <CodeGenerationSettings>
        <ShouldGenerateContext>true</ShouldGenerateContext>
        <OutputProjectName>MyModel</OutputProjectName>
        <OutputProjectFolder>\Generated\</OutputProjectFolder>
        <OutputPath>Generated\</OutputPath>
        <UseCustomTemplate>false</UseCustomTemplate>
        <MappingDefinitionType>Xml</MappingDefinitionType>
        <GenerateMultipleFiles>true</GenerateMultipleFiles>
        <OverrideToAutoProperties>true</OverrideToAutoProperties>
        <OutputMode>ProjectFolder</OutputMode>
      </CodeGenerationSettings>
      <SchemaUpdateSettings>
        <NamingScheme>UseDefaultNaming</NamingScheme>
        <NamePrefix />
        <AppendDateTimeStamp>true</AppendDateTimeStamp>
        <EnableDeployment>false</EnableDeployment>
        <DeploymentProject />
        <DeploymentDirectory />
        <SchemaUpdateStrategy>GenerateAndExecuteSchemaDDL</SchemaUpdateStrategy>
      </SchemaUpdateSettings>
      <BackendConfigurationSettings>
        <BackendConfiguration>
          <Backend>mssql</Backend>
          <Logging>
            <LogToConsole>False</LogToConsole>
          </Logging>
          <SecondLevelCache>
            <Enabled>True</Enabled>
            <CacheQueryResults>True</CacheQueryResults>
            <MaxObjectsInCache>22444</MaxObjectsInCache>
            <MaxQueriesInCache>1555</MaxQueriesInCache>
          </SecondLevelCache>
        </BackendConfiguration>
      </BackendConfigurationSettings>
      <UseSchemaAsNamespace>false</UseSchemaAsNamespace>
    </ModelSettings>
  • After save, double check that connectionStringName is MyContext in MyContext.cs.

That solved my generation problem, and avoided the '2 connection strings in the dropdown' problem.  I suppose when the context strings don't match, it triggers this behavior in the code generation dialog wizard.

Telerik: you probably have a defect in the code somewhere there in that wizard, or, at the least, need to warn of a mismatch in names.
0
Accepted
PetarP
Telerik team
answered on 01 Oct 2010, 04:04 PM
Hello Brian Womack,

 We do have some problems in the update wizard regarding the building of the project. The problem you have encountered occurs when there is a difference between the metadata in your application and the one in the build assembly. When such error is raised we are not able to dispose the database instance that was created for the update operation correctly. This instance is cached and the only way to dispose is to either restart the visual studio or change the connection string and thus create a new instance (what you have done).We have eliminated the need of a prebuild assembly for our next release and thus you should not experience such issues anymore.

Greetings,
Petar
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Design Time (Visual Designer & Tools)
Asked by
Brian
Top achievements
Rank 1
Answers by
Brian
Top achievements
Rank 1
PetarP
Telerik team
Share this question
or