I am experiencing the same exception while using the FluentAPI. I have a class defined that derives from a base class which defines some common properties.
interface
IModificationTracker
{
DateTime CreatedDate {
get
;
set
; }
String CreatedBy {
get
;
set
; }
DateTime UpdatedDate {
get
;
set
; }
String UpdatedBy {
get
;
set
; }
}
public
abstract
class
ModelBase : IModificationTracker
{
public
DateTime CreatedDate {
get
;
set
; }
public
String CreatedBy {
get
;
set
; }
public
DateTime UpdatedDate {
get
;
set
; }
public
String UpdatedBy {
get
;
set
; }
}
public
class
DeliverableType : ModelBase
{
public
Int64 ID {
get
;
set
; }
public
String Label {
get
;
set
; }
public
String Description {
get
;
set
; }
}
I then map it to the underlying table ...
protected
override
IList<MappingConfiguration> PrepareMapping()
{
List<MappingConfiguration> configurations =
new
List<MappingConfiguration>();
#region DeliverableType
MappingConfiguration<DeliverableType> typeMap =
new
MappingConfiguration<DeliverableType>();
typeMap.MapType(model =>
new
{
deliverable_type_id = model.ID,
deliverable_type_label = model.Label,
deliverable_type_description = model.Description,
created_date = model.CreatedDate,
created_by = model.CreatedBy,
updated_date = model.UpdatedDate,
updated_by = model.UpdatedBy
}).ToTable(
"deliverable_types"
);
//
// Identify contraints on fields
typeMap.HasProperty(c => c.Label).WithVariableLength(100);
// nvarchar(100)
typeMap.HasProperty(c => c.Description).WithInfiniteLength();
// nvarchar(MAX)
//
// Identify the Primary Key
typeMap.HasProperty(c => c.ID).IsIdentity(KeyGenerator.Autoinc);
//
// Define when to update the CreatedDate and UpdatedDate timestamps
typeMap.HasProperty(c => c.CreatedDate).IsCalculatedOn(DateTimeAutosetMode.Insert);
typeMap.HasProperty(c => c.UpdatedDate).IsCalculatedOn(DateTimeAutosetMode.InsertAndUpdate);
#endregion DeliverableType
configurations.Add(typeMap);
return
configurations;
}
And make it available through the context ...
public
partial
class
DbContext : OpenAccessContext
{
public
IQueryable<DeliverableType> DeliverableTypes
{
get
{
return
this
.GetAll<DeliverableType>();
}
}
// ... Connection configuration goes here
}
Then when I attempt to add a new entity to the table ...
using
(var ctx =
new
DbContext())
{
DeliverableType newType =
new
DeliverableType
{
CreatedBy =
"UNIT TEST"
,
UpdatedBy =
"UNIT TEST"
,
Description =
"TEST DESCRIPTION"
,
Label =
"TEST LABEL"
,
CreatedDate = DateTime.Now,
UpdatedDate = DateTime.Now
};
ctx.Add(newType);
ctx.SaveChanges();
}
I get the error ...
Telerik.OpenAccess.Exceptions.MetadataException: Mapping for field '<CreatedDate>k__BackingField' is specified in the file 'config', but the field is not present in the class 'InnovativeFoto.BLL.Models.DeliverableType'. --> FromMetadataContainer/namespace[InnovativeFoto.BLL.Models]/class[DeliverableType]/field[<CreatedDate>k__BackingField]
Any thoughts on what could be causing this? I did everything according to the instructions.
Here is the table schema if that helps ...
CREATE
TABLE
[dbo].[deliverable_types](
[deliverable_type_id] [
bigint
] IDENTITY(1,1)
NOT
NULL
,
[deliverable_type_label] [nvarchar](100)
NOT
NULL
,
[deliverable_type_description] [nvarchar](
max
)
NULL
,
[created_date] [datetime]
NOT
NULL
,
[created_by] [nvarchar](100)
NOT
NULL
,
[updated_date] [datetime]
NOT
NULL
,
[updated_by] [nvarchar](100)
NOT
NULL
,
CONSTRAINT
[PK_deliverable_types]
PRIMARY
KEY
CLUSTERED
(
[deliverable_type_id]
ASC
)
WITH
(PAD_INDEX =
OFF
, STATISTICS_NORECOMPUTE =
OFF
, IGNORE_DUP_KEY =
OFF
, ALLOW_ROW_LOCKS =
ON
, ALLOW_PAGE_LOCKS =
ON
)
ON
[
PRIMARY
]
)
ON
[
PRIMARY
] TEXTIMAGE_ON [
PRIMARY
]