2

I inherited a project (ASP.NET Web Forms) to update/upgrade. The project works just fine in VS 2013 when I run debug, but when I add a table to the SQL DB and "Update model from database" EF (4.0) is returning a bunch of errors like:

Error 34 Error 113: Multiplicity is not valid in Role 'Event' in relationship 'FK_FinanceInvoice_Events'. Because all the properties in the Dependent Role are nullable, multiplicity of the Principal Role must be '0..1'.

And it doesn't add the table to my model until I fix these errors, but if I change the Multiplicity setting (as some posts suggests to do) multiple other errors are coming up.

The thing is that the system and the EF Model works perfectly until I try to update it.

I also tried to create the model first and the "Generate DB", but this would drop the entire DB, and I cannot do that as it has lots of data in it.

One thing I noticed is that the Model.edmx does not have the .tt and context.tt files (I wanted to post a pic of my Solution Explorer, but I don't have enough reputation points). Is there a reason why these 2 files are missing from my model?

The second issue is that the database I need to update is in production and full of existing data.

I would greatly appreciate it if someone could point me to the right direction. Thank you!

EDIT: Jim Wooley suggested that the our DataModel was maybe created before T4, I don't know enough to find that out. Here is the content of the designer.cs file attached to the .edmx. Hopefully someone can tell me how it was created and how to update/modify the database and model

//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Data.EntityClient;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Serialization;

[assembly: EdmSchemaAttribute()]
#region EDM Relationship Metadata

[assembly: EdmRelationshipAttribute("EMSDataModel", "FK_ActivityLogs_Log", "UserLog", System.Data.Metadata.Edm.RelationshipMultiplicity.ZeroOrOne, typeof(EMS.Data.UserLog), "ActivityLog", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(EMS.Data.ActivityLog), true)]

//The rest i removed for brevity

namespace EMS.Data
{
    #region Contexts

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    public partial class EMSDataModelContainer : ObjectContext

    //The rest i removed for brevity

    #region Entities

/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmEntityTypeAttribute(NamespaceName="EMSDataModel", Name="AccommodationDetail")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class AccommodationDetail : EntityObject

    //The rest i removed for brevity

    #region ComplexTypes

/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmComplexTypeAttribute(NamespaceName="EMSDataModel", Name="CheckCityExists_Result")]
[DataContractAttribute(IsReference=true)]
[Serializable()]
public partial class CheckCityExists_Result : ComplexObject
    //The rest i removed for brevity

}

I hope someone can redirect me to making changes to the production database and consequently the model.

EDIT: I am using Visual Studio 2013 and this post didn't work for me How to Use Entity Framework 4 with Visual Studio 2013

Community
  • 1
  • 1
emadev
  • 71
  • 2
  • 6
  • don't know, maybe try creating new solution, and create new model from the scratch – vmg Feb 12 '14 at 19:39
  • that mean update tons of code if some model properties are changed – emadev Feb 12 '14 at 19:52
  • It sounds like the person who created the model either tweaked it manually or did it before the data schema was changed in the database. EF works fine if the model doesn't agree with the schema in database first, but regenerating from database will cause the model to be updated. Customizations that were previously added may need to be updated based on the new schema. You should be able to make the appropriate changes to the model manually and retain your database and application code without changes if you work through the issues. – Jim Wooley Feb 12 '14 at 20:09
  • Since you said the .tt files are not present, I wonder if you are using an earlier version of EF before the T4 integration was exposed. – Jim Wooley Feb 12 '14 at 20:10
  • It could be. The EF version detected is 4.0. If that is the case how should I proceed? – emadev Feb 12 '14 at 20:28

1 Answers1

0

All these issue were solved by using VS 2010. I imported the project in VS 2010, updated the model from database, successfully imported new tables. No errors were created and we are all happy. Too bad I cannot use my new VS 2013 Pro for which I spent money to work on this project. I wish new VS version could detect old projects and adapt or at least alert the user of potential issues

emadev
  • 71
  • 2
  • 6