I had a column in a table which type was nvarchar(50) and had entity framework to generate te mappings and the model from that table for an asp mvc project, but after tricky error i found that the 50-length was to short for the type of field. I already modified the column to nvarchar(100) and on the mappings folder the Table.cs file has a line this.Property(t => t.AColumn).HasMaxLength(50), i can guess that modifing the value to 100 should do the work, so is this all what i need or do i need Entity Framework to re-do everything, another question is how to make Razor, Entity or any tool to show some kind of message related to the mappings constrains.
Edit:
The error was that AColumn was too short for a form field but it didn't show a error message, it just shows errors from the model attributes or type constrains but not things defined on the mappings like HasMaxLength(50), i want to be able to show the length error on the view if possible. The app just failed with an EntityFramework exception with a rather complicated traceback.
Thanks.
Related
I am working with entity framework 6 with database 1st approach. I changed the datatype of my columns in the table and after updating my model I got the following error:
Error 1 Error 2019: Member Mapping specified is not valid. The type
'Edm.Int32[Nullable=False,DefaultValue=]' of member 'Warranty' in type
'pjModel.Bill' is not compatible with
'SqlServer.nvarchar[Nullable=False,DefaultValue=,MaxLength=50,Unicode=True,FixedLength=False]'
of member 'Warranty' in type 'pjModel.Store.Bills'.
what I understand that there is some compatibility issue between datatypes of framework and sql server.
Also when I opened the .edmx file with XML viewer, it clearly shows that changes are propagated in the model i.e data type has been updated, but in the diagram view when I right click the particular column it still shows the old datatype.
I can provide more information if required.
The issue has been resolved. I manually change the type from the diagram view and then it get mapped with the model class.
Same problem here, using EF6, after changing on a database table a field from int to bit.
It was not enought to delete property from model designer, and create it again, as the table mapping refered to the old type.
I guess this could be useful for similar cases. The only way to solve it (unless you don't mind deleting entity and updating model from database) is to edit your Entity Data Model as text (by default, DataModel.edmx), locate the entity as <Entity> node inside <Schema> node and find the desired property that indicates the old type. As an example:
<Property Name="MyProperty" Type="int" Nullable="false" />
Simply change Type attribute to the desired type, return to Visual Studio, save the edmx file, and rebuild.
I have a strange error, I'm using code first entity framework 6 with a dynamic data web app. Whenever I have a relationship to a table called "URL" (or "Url"), I get the following error when editing the related object:
'microsoft.aspnet.entitydatasource.entitydatasourcewrapper' does not contain a property with the name "Urls"
I can change the name of the class to anything else and it works. (I used 'siteurl'). Why is this word special?
It looks like the name URL is being pluralized by dynamic data site. That's what happened to me for a field name. I unchecked the "Pluralize or singularize generated object names" on the "Choose Your Database Objects and Settings dialog box in the Model and it worked. :)
I am creating a model from an existing DB using EF5 with a table containing a geography column. The model for the table works perfectly fine. However if I try to map a stored procedure which simply selects the geography column I cannot map this column in a Function Import. In the Column Information the EDM Type is set to "Not Supported". However the model maps the geography type as a parameter without a problem.
IDE is VS2012 Premium, framework .NET4.5
Any idea's?
I ended up creating the complex type without the my geography column through function import and afterwards added the scalar property of type Geography. Though it wouldn't automatically map the column for me. So I looked through EDMX with the XML editor looking for the mapping details for the function and added the mapping information manually. After that everything worked fine.
Oké, so I found one way to answer this myself. To anyone interested: I've manually created a new Scalar Property of the Geography type on the complex type which results from the SP. Now somehow the value maps. Looks to me the editor is not able to create a property, but mapping an existing property is no problem. To me this seems like a bug in the editor.
Also have a look at this thread: Build error when using VS 11, .NET 4.5 and Entity Framework
I am using EF 4 to generate my entities from the database. I get the following error while I am trying to compile my Model assembly (the edmx file in a separate assembly). I get the error only on tables, who have there primary keys as identity columns. Is that an issue? or am I just making wrong judgements?
Error 11007: Entity type 'tableName' is not mapped.
Steps
Using Entity data model wizard I created my Model (edmx file).
Right click the edmx file and Add Code Generation Item to create the entities (using Ado.net self tracking entity generator).
Move the entities to a different assembly by moving the x.tt and edit it to point to the edmx file in a different assembly.
Now the entity and model (edmx) are in different assembles, to enabled me to have a multi tier application.
I am unable to build the Model assembly and I get the error
Error 11007: Entity type 'tableName' is not mapped.
I have checked for solutions online. Yes, all my tables have a primary key and association between them is defined with terms of foreign keys. Any pointers on this?
Thanks,
Dolly
I'm making an OData service and using an EDM to map the structure of my database and specify associations between tables and create Navigation Properties.
I've imported my tables into the EDM using the wizard. Things compile fine until I put in associations. I'm sure I've been able to do this before but for some reason it is screwing up.
I have a table Attribute
AttributeId int PK
AttributeName varchar(100)
and
AttributeItem
AttributeItemId int PK
AttributeID int
AttrributeItemValue varchar(100)
I want to link AttributeId between the two tables with a 0..1 to * relationship (from Attribute to AttributeItem).
I'm constantly getting problems. initially this error:
Error 3027: No mapping specified for the following EntitySet/AssociationSet - AttibuteAttributeItem
Then once I've fiddled with the mapping details of the association I get this error:
Error 3024: Problem in mapping fragments starting at line 91: Must specify mapping for all key properties (AttributeItemId, AttributeId) of End AttributeItem in Relationship AttributeAttributeItem.
I've no idea why it's doing this.
Any idea what I'm missing?
thanks,
B
double click on Assotiation link and set up Referential Constraint. It shouldn't be empty. Use "Generate Database" after that to update EDM model internals.
Also consider to right click on edmx file in solution exprorer and select "Open With..." and open it with XML editor to see at the line of error (91).