Code First Default Mapping missing DateTime field in database

2 posts, 0 answers
  1. Sarfraz
    Sarfraz avatar
    1 posts
    Member since:
    Oct 2012

    Posted 01 Oct 2012 Link to this post

    I am using OpenAccess.CodeFirst and OpenAccess.CodeFirst.Sample version 2012.2.924.1 via NuGet, just modified the product with a datetime property like following

    public class Product
    {
        public int ID { get; set; }
        public string ProductName { get; set; }
        public DateTime CreateDate { get; set; }
        public decimal Price { get; set; }
    }

    and mapping to auto/default mapping

    MappingConfiguration<Product> productConfiguration = new MappingConfiguration<Product>();
    productConfiguration.MapType().ToTable("Products");
    productConfiguration.HasProperty(x => x.ID).IsIdentity(KeyGenerator.Autoinc);

    but the generated schema does not have datetime column

    -- OrmTest.Product
    CREATE TABLE [Products] (
        [ID] int IDENTITY NOT NULL,             -- <ID>k__BackingField
        [Price] numeric(20,10) NOT NULL,        -- <Price>k__BackingField
        [ProductName] varchar(255) NULL,        -- <ProductName>k__BackingField
        CONSTRAINT [pk_Products] PRIMARY KEY ([ID])
    )
    go

    I was surprised as i have used the version 2012.1.427.1 package in past, it creates schema correctly.

    also
    if i use the explicit mapping like following

    MappingConfiguration<Product> productConfiguration = new MappingConfiguration<Product>();
    productConfiguration.MapType(x => new
    {
        ID = x.ID,
        Price = x.Price,
        CreatedDate = x.CreateDate,
        ProductName = x.ProductName
    }).ToTable("Products");
    productConfiguration.HasProperty(x => x.ID).IsIdentity(KeyGenerator.Autoinc);

    i get the desired results,

    -- OrmTest.Product
    CREATE TABLE [Products] (
        [ID] int IDENTITY NOT NULL,             -- <ID>k__BackingField
        [Price] numeric(20,10) NOT NULL,        -- <Price>k__BackingField
        [CreatedDate] datetime NOT NULL,        -- <CreateDate>k__BackingField
        [ProductName] varchar(255) NULL,        -- <ProductName>k__BackingField
        CONSTRAINT [pk_Products] PRIMARY KEY ([ID])
    )
     
    go

    I would like to use the default/auto mapping as some of my other classes have more fields in a time management related project.

    Regards

  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 02 Oct 2012 Link to this post

    Hi Sarfraz,

     I have confirmed that this is a bug on our side that got introduced when we added support for struct data structures in our fluent API. We will address the bug and a fix will be introduced with our next official release scheduled for mid of October. 
    Please find your Telerik points updated for bringing that but to our attention.

    All the best,
    Petar
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
  3. DevCraft banner
Back to Top