Entity Framework is padding out my text fields although they are not Fixed Length - asp.net-mvc-3

I am building an MVC3 site using Entity Framework 4 and I'm having a problem with fixed length fields.
When I look at my code during debug it shows that MyEntity.Title="Hello name " with the title padded out to the maximum length of the field.
This is usually a question of having fixed field length in the EDMX file or using a char data type on the underlying database rather than a varchar. In this case neither of those is correct, however it is possible that the problem fields were of fixed length originally. I have manually changed each field in the EDMX ( and the model has been regenerated ) and the fields were never fixed length in the database ( which was the starting point for the application ) so I guess that the need to pad out the fields is being stored somewhere in the Entity Framework configuration and hasn't been updated.
The problem occurs in new records when they are added to the database- when the object is created the Title will be correct, when it is instanciated from the database it is padded.
What do I need to do in order to get rid of the padding, which is really screwing up my string comparisons unless I trim everything?

It turns out that in the .EDMX file the padded files were still listed as nchar. This wasn't visible through the Model Editor, the only way to change it was to right-click on the model in Visual Studio and select "open with..." then use an XML editor. The offending fields looked like this:
<Property Name="MyProperty" Type="nchar" Nullable="false" MaxLength="50" />
Changing the Type to nvarchar and running the template again seemed to clear the problem up.

Existing fields do not get updated in the model when you update it from the database. You either have to delete the entities from the model, or manually change those fields to the new values.
Check the property types in the Model Browser and make sure they are correct.

Change your Title field to have the Fixed Length property set equal to true. It's probably defaulting to none :)
Make sure you make the change in the dbase first and then update your edmx.

Related

how to change columns position in vb6?

I am working with a spread designer in visual basic 6 and am looking to change the display index of my table. I am adding extra columns and I need to rearrange them to match another form.
I am using visual basic 6 with spread designer 6.0
I have tried the below when loading the form:
lstTheLines.Col(1).DisplayIndex = 1
lstTheLines.Columns(25).DisplayIndex = 2
does anyone know how to do this without having to delete and re-add all columns?
The best way I found so far was to add the columns in the place I want using the spread designer and create an Enum in the code for each column index. This way I can give the columns a name and use that instead when populating the data. The benefit to this is that I can now rename the columns or add new ones and I just need to change the names around in the Enum given that the column type is correct.

Convert Single line text to Multiline text (MS CRM 2016)

I would ask about capability to change the filed datatype from Single line to Multiline without delete this field.
Actually the CRM form editor is disable the data type option set after filed created, so I think I have to change the data type via Database
but I need to know if is it possible to do that, and if we change the data type from the database is it will change the filed from single line shape to multiline in the form.?
because my CRM is online so I need confirm is it possible, to ask Microsoft to do it for me.
Best regards .
It is not possible to convert a single line text field to a multi-line text field. Instead you should create a new multi-line text field and move the data from the old field to the new field.
If you were on-premise, you should not be making direct changes to the database (and there is no way Microsoft would be doing so for you online):
Modifying tables, stored procedures, or views in the database is not
supported.
Yes, as Henrik mentions, it's not possible, but tools can make it appear to be for all practical purposes ;)
The Attribute Manager (it's a plugin for the the XrmToolBox) will do this for you. It's in beta, so don't run it in prod without testing it in another environment first.
Just select your field, check Convert Attribute Type (optionally check Migrate Data if you want it migrated) and execute. You'll need to do it in each environment.

Changing an existing field's format without dropping, recreating

I've tried changing the format attribute of a field (from Text to URL) without dropping the column and recreating it. I know this isn't supported, but it seemed simple so I thought I'd give it a try.
I came up with this SQL script based on this post
UPDATE Attribute SET AttributeLogicalTypeId = 'url' WHERE AttributeId in
(
SELECT AttributeId FROM Attribute ab where ab.LogicalName in ('new_linkedin') and ab.EntityId in
(Select EntityId from Entity where LogicalName in ('account', 'contact'))
)
According to the UI, when I go back in the field's configuration, this seems to have worked. But the problem is the value in the field is never turned into an actual URL, whereas the built-in field websiteurl does it properly (value turns bold and underlined).
Am I missing something else to update in the database ?
Hmm, removing the field from the form(s), publishing the form(s) and then putting the field back on the form(s) and publish yet again did it.

Convert Int32 to Oracle number(5) with EF4

I am using EF 4 (database first, model fully generated from it) with an oracle 10g database and I have a problem with one field.
My field is defined as a NUMBER(5) in my database. In my model, EF has defined it as a short.
My problem is that i have some values that are greater than 32,767 (max of a short)
I found this post : Entity Framework generates short instead of int. I follow the instruction and it works, my model contain now Int32 values.
But I have a new problem :
Error 2019: Member Mapping specified is not valid. The type 'Edm.Int32[Nullable=True,DefaultValue=]' of member 'XX' in type 'Model.XXX' is not compatible with 'OracleEFProvider.number[Nullable=True,DefaultValue=,Precision=5,Scale=0]' of member 'XX' in type 'Model.Store.XXX'.
This error is always show in the Error List tab of Visual Studio. However, the build success, and it half works:
read a value in database works
write a value do not work : 99999 was transformed in -31073 (see edit)
Is there a solution to have it works on both ways ?
BTW, is there any way to tell entity to use int32 for oracle INTEGER fields ? It use decimal by default.
EDIT
While debuging step by step, I found why my value was -31073. I forgot this line :
dao.Value = (short)dto.Value;
My two values were int, but the implicit conversion in short was the origin.
I found how to remove the error.
I edited the edmx file in xml mode, found my field in the ssdl section :
<Property Name="SIT_INSEE" Type="number" Precision="5" />
I removed the Precision="5" and the warning disappeared.
Just to add my two cents in case anyone else is having similar problems. I noticed if you add the following to mappings in web.config and then recreate the edmx model from scratch (delete it and re-generate from database) it resolves some of these issues. Where simply adding the values to web.config resolved nothing (probably re-generating some of the code behind the scenes would be my guess).
<oracle.dataaccess.client>
<settings>
<add name="int32" value="edmmapping number(9,0)" />
</settings>
</oracle.dataaccess.client>

"Cannot change DataType of a column once it has data" error in Visual Studio 2005 DataSet Designer

I've got a DataSet in VisualStudio 2005. I need to change the datatype of a column in one of the datatables from System.Int32 to System.Decimal. When I try to change the datatype in the DataSet Designer I receive the following error:
Property value is not valid. Cannot change DataType of a column once
it has data.
From my understanding, this should be changing the datatype in the schema for the DataSet. I don't see how there can be any data to cause this error.
Does any one have any ideas?
I get the same error but only for columns with its DefaultValue set to any value (except the default <DBNull>). So the way I got around this issue was:
Column DefaultValue : Type in <DBNull>
Save and reopen the dataset
Since filled Datatables do not entertain a change in the schema a workaround can be applied as follows:
Make a new datatable
Use datatable's Clone method to
create the datatable with the same
structure and make changes to that
column
In the end use datatable's ImportRow
method to populate it with data.
HTH
For those finding this via Google and you have a slightly different case where your table has got data and you add a new column (like me), if you create the column and set the datatype in separate statements you also get this same exception. However, if you do it in the same statement, it works fine.
So, instead of this:
var column = myTable.Columns.Add("Column1");
column.DataType = typeof(int); //nope, exception!
Do this:
var column = myTable.Columns.Add("Column1", typeof(int));
I have found a work around. If I delete the data column and add it back with the different data type, then it will work.
Close the DataSet in the visual designer
Right click the dataset, choose Open With...
Choose XML (Text) Editor
Find the column in the XML, in your dataset it will look something like:
<xs:element name="DataColumn1"
msprop:Generator_ColumnVarNameInTable="columnDataColumn1"
msprop:Generator_ColumnPropNameInRow="DataColumn1"
msprop:Generator_ColumnPropNameInTable="DataColumn1Column"
msprop:Generator_UserColumnName="DataColumn1"
type="xs:int"
minOccurs="0" />
Change the type="xs:int" to type="xs:decimal"
Save and close the XML editor
You may need to right click the DataSet again and choose Run Custom Tool
Its an old Question but it still can happen at VS 2019
Solution:
Change the DefaultValue to <DBNull>
Save the Dataset
Close the DataSet Designer
Re-Open the Designer
Now it should be possible to change the type without any problem.

Resources