This is a migrated thread and some comments may be shown as answers.

Code First Default Mapping missing DateTime field in database

1 Answer 65 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sarfraz
Top achievements
Rank 1
Sarfraz asked on 01 Oct 2012, 02:51 PM
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

1 Answer, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 02 Oct 2012, 03:20 PM
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!
Tags
Data Access Free Edition
Asked by
Sarfraz
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Share this question
or