How do I manually edit table mappings in ADO.NET in Visual Studio 2010? - entity-framework

I can't seem to find the answer to what I think is an easy question. I have a Entity model I just created and I want to set the name of the table and the columns by hand. I can see the "mapping details," but how do I edit them or add to them?

It appears the answer is, you can't without going into the XML. You can use the Entity Framework Power Pack to customize the templates for generation, but there's no direct GUI for editing the mappings.

I open the folder where edmx file in, look into all files in it, and find a possible solution.
I advice install the notepad++ first, then right click on the Edmx File in file explorer, and click Edit with Notepad++ then the xml file content will show, or you can directly open the Edmx file by notepad.exe
You'll see something like this on the top part of the file:
<EntityType Name="DataTableName">
<Key>
<PropertyRef Name="id" />
</Key>
<Property Name="DataColumn1" Type="bigint" Nullable="false" />
<Property Name="DataColumn2" Type="datetime" Nullable="false" />
<Property Name="DataColumn3" Type="nvarchar" MaxLength="255" />
<Property Name="DataColumn4" Type="nvarchar" MaxLength="255" />
</EntityType>
What I want to do is remove DataColumn4, I first open the Edmx File in VS and directly click on the column name in the VS UI and press Delete on the keyboard, and you'll find that in the Mapping Detail Window, the right side of DataColumn4 property will be empty, but in the left side the DataColumn4 still exist.
Then, Open the edmx file using Step 1, remove the property in the Step 2 and save the file.
Remove--> <Property Name="DataColumn4" Type="nvarchar" MaxLength="255" />
Restart visual studio, and open the edmx again you'll find DataColumn4 disappear, and I try connect to DB and manipulate Data, works fine.

If you have your .edmx file open in Visual Studio, you should be able to simply right-click on a table or a column in the table and choose 'rename'. Once you change the name it will be reflected in the Mapping Details window.

You can edit the names easily... just click on the name (when the item is already selected) in the 'class diagram' or the table representation in the edmx file and type the new name. If the text does not become selected and editable when you click on it, you can press F2, the standard Windows key to raname an object. Note: you cannot edit the name in the mapping window.
After editing the names, you can right click on the entity and select 'Generate Database from Model...' option to update the names in the database.
Also, see this post for more information.

Here a solution that works on VS 2010. If you Rename an entry, afterwards run "Generate Database from Model..." two times. IN the first run, the mapping is adjusted but you still get a (let me say "compiler") error. In the second run, everything is fine.
I just tested it two times. Worked perfectly.

Related

Model.tt T4 does not generate custom enum files while they have no External Type set

I have a Model.edmx file to which I added a custom Enum type (be it through "convert to enum" or "Add enum type"). Let's call this enum "MyEnum"
I add to this enum some members:
MyMemberOne
MyMemberTwo
MyMemberThree
Mistakingly, i check Reference external type and set it to something, let's say MyExternalEnum, and save the edmx.
Then I realize this is not what I want so I edit the enum (Right-click > edit) and uncheck Reference external type, click OK and save again.
When I execute the automatically generated Model.tt (Right click > Run custom tool), I expect a file MyEnum.cs to be created.
This is not the case
Double-checking to see if Reference external type is uncheked yields no result.
Why ? What is hapenning ?
I peered through Model.edmx in a xml text editor, and saw MyEnum was encoded as such:
<EnumType Name="MyEnum" a:ExternalTypeName="" xmlns:a="http://schemas.microsoft.com/ado/2006/04/codegeneration" >
<Member Name="MyMemberOne" />
<Member Name="MyMemberTwo" />
<Member Name="MyMemberThree" />
</EnumType>
This should be OK because ExternalTypeName is empty, but for some reason the Model.tt T4 file generator treats an empty string as a real value, preventing enum code generation from happening.
Removing a:ExternalTypeName="" xmlns:a="http://schemas.microsoft.com/ado/2006/04/codegeneration" from the EnumType tag and saving allows Model.tt to generate the file MyEnum.cs correctly.
<EnumType Name="MyEnum"> <!-- This is ok -->
<Member Name="MyMemberOne" />
<Member Name="MyMemberTwo" />
<Member Name="MyMemberThree" />
</EnumType>
I have seen nothing in the Model.tt hinting to why this behavior exists nor if it is intended (but I highly doubt it...).
I expected somewhere in there to be a if (ExternalTypeName != null) //Do not generate file, instead of a if (ExternalTypeName != null && ExternalTypeName != String.Empty), but the actual mistake is not so easy to spot.

How to create a repository in ATG?

i would like to know how to create a new repository in ATG. like what all steps are needed to be included? Do i need to create a properties file?
In order to create a new repository, You need to follow these steps if you want to create a repository that uses sql database in as the datastore.
Create a properties file
Create tables you want to map to the repository
Create a definition XML files to map repository item-descriptors and their properties to the respective tables.
MyRepository.properties
$class=atg.adapter.gsa.GSARepository
repositoryName=MyRepository
definitionFiles=atg/test/repositories/MyRepository.xml
XMLToolsFactory=/atg/dynamo/service/xml/XMLToolsFactory
transactionManager=/atg/dynamo/transaction/TransactionManager
idGenerator=/atg/dynamo/service/IdGenerator
dataSource=/atg/dynamo/service/jdbc/JTDataSource
lockManager=/atg/dynamo/service/ClientLockManager
The above properties files ensures that a new repository component is created and MyRepository.xml will be marked as its definition file.
The content of the MyRepository.xml file should be something like below...
MyRepository.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE gsa-template SYSTEM "http://www.atg.com/dtds/gsa/gsa_1.0.dtd">
<gsa-template>
<header>
<name>New Repository creation</name>
<author>Jyothi Prasad Buddha</author>
</header>
<item-descriptor name="myRepo" cache-mode="simple">
<table name="my_repo" type="primary" id-column-names="id">
<!-- properties that may (or may not) be used as primary keys -->
<property name="name" data-types="String" />
<property name="age" data-types="int" />
</table>
</item-descriptor>
</gsa-template>
However you will have to create the the necessary tables before you start atg instance. The above xml files refers to a table named my_repo which has comlumns name and age.
Yes you need to create properties file's for more details you can read RepositoryGuide.pdf from Oracle.
for more detail you can read below blog
http://immuraliraj.blogspot.in/2011/12/atg-repository-basic-concepts.html
Just type
"ATG Creating a repository" on Google
and you would get lot of relevant results on the first page itself. Also be specific which version of ATG are you using, and what you have already done/found in your research. (just a suggestion, so you get good responses).
Yes, you need a properties file when creating a custom repository component. There are a lot of blogs that answer your question with detailed steps.
Check this for example

Avoid generating header comments with Hibernate generation tools

When generating DTO objects, hibernate tools generate comments in the header:
// Generated 22 avr. 2013 20:29:27 by Hibernate Tools 3.4.0.CR1
Every generation the comments change (as they contains the generation date/time).
The problem is that in my SVN I end up having many non-usefull changes, so I have to check every single generated file to see whether to commit (if it contains actuals changes) or override it (if it's only the header).
Is there a way to avoid generating said header ?
Thank you.
You would have to customize the Freemarker template which is found in hibernate-tools.jar. Navigate to the /pojo/Pojo.ftl and remove the line // Generated ${date} by Hibernate Tools ${version}.
Checking this out might help: https://forum.hibernate.org/viewtopic.php?f=6&t=989777&view=next
An example of a Hibernate tool Ant task (by specifying templatepath and hbmtemplate attributes:
<hibernatetool destdir="hibernate-model-gen/pojo" templatepath="hibernate-model-gen/customized-templates">
<jdbcconfiguration configurationfile="hibernate-model-gen/hibernate.cfg.xml" packagename="open.pub.proto.core.model" revengfile="hibernate-model-gen\gen-conf\hibernate.reveng.xml" detectmanytomany="true" />
<hbmtemplate templateprefix="pojo/" template="pojo/Pojo.ftl" filepattern="{package-name}/{class-name}.java">
<property key="jdk5" value="true" />
<property key="ejb3" value="true" />
</hbmtemplate>
</hibernatetool>

Reset ADO.NET schema

I modified a schema (set a field to be non-nullable), but when I try to recreate the mapping with ADO.NET I only see the old schema.
The .edmx file looks like this:
<EntityType Name="STG_DW_BUF_CODE_D">
<Key>
<PropertyRef Name="BUF_CODE_KEY" />
</Key>
<Property Name="BUF_CODE_KEY" Type="number" Nullable="false" />
…
<EntityType Name="STG_DW_REGION_D">
<Property Name="REGION_KEY" Type="number" />
The STG_DW_REGION_D view should have Nullable="false" like the view above it.
I can confirm the new schema has this field non-nullable through another SQL application, but I can't get ADO.NET to notice.
I tried erasing the model and recreating it. I tried closing visual studio and starting it up again. It still sees the old schema.
Does anyone know how to reset it? Any suggestions?
This is either a bug in ADO.NET or ODP (Oracle's connection to Linq). If you add a field it will remove the cached schema and pull in a new schema with updated field attributes.

Alfresco Share constraint default empty value

i have a simple question.
Is there a simple config file or line that can be edited in order to achieve this:
I need that constraints from Alfresco content model have an empty field (like "unselected") in Advanced Search and Edit Metadata forms.
So a constraint of:
<constraint name="custom:customList" type="LIST">
<parameter name="allowedValues">
<list>
<value>first type</value>
<value>second type</value>
</list>
</parameter>
</constraint>
I need to view these in a "SELECT" form but with the first selection empty, like:
<select>
<value></value>
<value>first type</value>
<value>second type</value>
</select>
Hope I made that clear.
P.S. I don't want to insert a in the custom content model XML file. There should be another way to achieve this.
Thanks to all.
You need to override the presentation logic, i.e. customize or create a new form control template. The default one is implemented in selectone.ftl, you can customize it or start from it for a brand new control template which you can later assign to your metadata field in the forms configuration.