Dave
Dave

Reputation: 659

Is it possible to prevent the SQL Producer from overwriting just one of the tables columns?

Scenario: A computed property needs to available for RAW methods. The IsComputed property set in the model will not work as its value will not be available to RAW methods.

Attempted Solution: Create a computed column directly on the SQL table as opposed to setting the IsComputed property in the model. Specify that CodefluentEntities not overwrite the computed column. I would than expect the BOM to read the computed SQL field no differently than if it was a normal database field.

Problem: I can't figure out how to prevent Codefluent Entities from overwriting the computed column. I attempted to use the production flags as well as setting produce="false" for the property in the .cfp. Neither worked.

Question: Is it possible to prevent Codefluent Entities from overwriting my computed column and if so, how?

Upvotes: 0

Views: 181

Answers (2)

Dave
Dave

Reputation: 659

Alternate Solution: An alternate solution is to execute the following the TSQL script after the SQL Producer finishes generating.

ALTER TABLE PunchCard DROP COLUMN PunchCard_CompanyCodeCalculated
GO

ALTER TABLE PunchCard
ADD PunchCard_CompanyCodeCalculated AS CASE
       WHEN PunchCard_CompanyCodeAdjusted IS NOT NULL THEN PunchCard_CompanyCodeAdjusted
       ELSE PunchCard_CompanyCode
END

GO 

Additional Configuration Needed to Make Solution Work: In order for this solution to work one must also configure the BOM so that it does not attempt to save the data associated with the computed columns. This can be done through Model using the advanced properties. In my case I selected the CompanyCodeCalculated property. Went to advanced settings. And set the Save setting to False.

Question: Somewhere in the Knowledge Center there is a passing reference on how to automate the execution SQL Scripts after the SQL Producer finishes but I can not find it. Anybody now how this is done?

Post Usage Comments: Just wanted to let people know I implemented this approach and am so far happy with the results.

Upvotes: 0

user1711036
user1711036

Reputation: 51

The solution youre looking for is here

You can execute whatever custom T-SQL scripts you like, the only premise is to give the script a specific name so the Producer knows when to execute it.

i.e. if you want your custom script to execute after the tables are generated, name your script

after_[ProjectName]_tables.

Save your custom t-sql file alongside the codefluent generated files and build the project.

In my specific case, i had to enable full-text index in one of my table columns, i wrote the SQL script for the functionality, saved it as

`after_[ProjectName]_relations_add`

Heres how they look in my file directory

file directory

Upvotes: 1

Related Questions