Bug #64216 Generated script contains varbinary without length and wrong alter table
Submitted: 2 Feb 2012 23:04 Modified: 24 Aug 2012 23:24
Reporter: Arthur Alexeev Email Updates:
Status: Closed Impact on me:
Category:Connector / NET Severity:S2 (Serious)
Version:6.4.4. OS:Windows (windows 7)
Assigned to: Fernando Gonzalez.Sanchez CPU Architecture:Any

[2 Feb 2012 23:04] Arthur Alexeev
I'm using entity framework code-first approach to create tables in database.
This code is used to create tables:

var dbCreationScript = ((IObjectContextAdapter)context).ObjectContext.CreateDatabaseScript();

But generated script has errors.
1. It creates varbinary type from byte[] and does not specify the length of varbinary like "varbinary(0)".
With varbinary I get exception that script is incorrect.
With varbinary(0) it goes ok.

2. Incorrect alter table commands pointing to nonexist tables.

For example this class is used as entity:

    public partial class ShippingMethod : BaseEntity, ILocalizedEntity
        private ICollection<Country> _restrictedCountries;

        /// <summary>
        /// Gets or sets the name
        /// </summary>
        public virtual string Name { get; set; }

        /// <summary>
        /// Gets or sets the description
        /// </summary>
        public virtual string Description { get; set; }

        /// <summary>
        /// Gets or sets the display order
        /// </summary>
        public virtual int DisplayOrder { get; set; }

        /// <summary>
        /// Gets or sets the restricted countries
        /// </summary>
        public virtual ICollection<Country> RestrictedCountries
            get { return _restrictedCountries ?? (_restrictedCountries = new List<Country>()); }
            protected set { _restrictedCountries = value; }

As you can see its called "ShippingMethod". So I get create table shippingmethod command inside script that works fine and such table is created.
But I also get ALTER TABLE ShippingMethodCountry that does not exist and should not be exist because no such class was ever created.
As I understand it is created because of private ICollection<Country>. But this alter table should point to ShippingMethod table instead (as i think).

(trying to implement mysql in nopcommerce)


How to repeat:
I can post full source to fileshare. But i think you can repeat it with class mentioned.
[24 Aug 2012 23:24] John Russell
Added to changelog for 6.4.6, 6.5.5, 6.6.0: 

When using the Entity Framework Code First approach, the generated
could be incorrect: Missing length specifier for data types, such as
VARBINARY instead of VARBINARY(n). ALTER TABLE statements referring
to nonexistent tables, when private members were specified inside the
main class.