This question is locked. New answers and comments are not allowed.
Hi,
I have created a new fluent project.
I have a base class :
I have 2 classes that inherit from base class :
In mapping code :
1) Why in the method :
I cant't write :
configuration.HasAssociation(m => m.MetaEnumItemList).HasConstraint((x,y)=>x.Id == y.MetaEnumId) .ToColumn("MetaEnumId").IsDependent();
==> Error 5 A property from the configured type does not take part in the expression.
2) I create a new odata service v2 :
When i execute the service ==> The entity type 'MetaEnumItem' does not have any key properties. Please make sure the key properties are defined for this entity type.
Kind regards
I have created a new fluent project.
I have a base class :
[DataContract]
public
abstract
class
ModelMetadataBase : IModelBase
{
[DataMember]
public
int
Id
{
get
{
return
_id; }
set
{ _id = value; }
}
protected
int
_id;
}
I have 2 classes that inherit from base class :
[KnownType(
typeof
(ModelMetadataBase))]
[KnownType(
typeof
(IList<MetaEnumItem>))]
[DataContract]
public
class
MetaEnum : ModelMetadataBase
{
[DataMember]
public
string
Name
{
get
{
return
_name; }
set
{ _name = value; }
}
private
string
_name;
[DataMember]
public
IList<MetaEnumItem> MetaEnumItemList
{
get
{
return
_metaEnumItemList; }
set
{ _metaEnumItemList =
new
List<MetaEnumItem>(value); }
}
private
IList<MetaEnumItem> _metaEnumItemList =
new
List<MetaEnumItem>();
}
[KnownType(
typeof
(ModelMetadataBase))]
[KnownType(
typeof
(MetaEnum))]
[DataContract]
public
class
MetaEnumItem : ModelMetadataBase
{
[DataMember]
public
int
MetaEnumId
{
get
{
return
_metaEnumId; }
set
{ _metaEnumId = value; }
}
private
int
_metaEnumId;
[DataMember]
public
int
Value
{
get
{
return
_value; }
set
{ _value = value; }
}
private
int
_value;
}
In mapping code :
public
MappingConfiguration<MetaEnum> GetMetaEnumMappingConfiguration()
{
MappingConfiguration<MetaEnum> configuration = GetMetaEnumClassConfiguration();
PrepareMetaEnumPropertyConfigurations(configuration);
PrepareMetaEnumAssociationConfigurations(configuration);
return
configuration;
}
public
MappingConfiguration<MetaEnum> GetMetaEnumClassConfiguration()
{
var configuration =
new
MappingConfiguration<MetaEnum>();
configuration.MapType().Inheritance(InheritanceStrategy.Vertical).ToTable(SchemaMetadata +
".MetaEnum"
);
return
configuration;
}
public
void
PrepareMetaEnumPropertyConfigurations(MappingConfiguration<MetaEnum> configuration)
{
configuration.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Autoinc).HasFieldName(
"ModelMetadataBase._id"
).ToColumn(
"Id"
).IsNotNullable().HasColumnType(
"int"
);
configuration.HasProperty(x => x.Name).ToColumn(
"Name"
).HasColumnType(
"varchar"
).IsNotNullable().HasLength(50);
}
public
void
PrepareMetaEnumAssociationConfigurations(MappingConfiguration<MetaEnum> configuration)
{
configuration.HasAssociation(m => m.MetaEnumItemList).HasConstraint().ToColumn(
"MetaEnumId"
).IsDependent();
}
public
MappingConfiguration<MetaEnumItem> GetMetaEnumItemMappingConfiguration()
{
MappingConfiguration<MetaEnumItem> configuration = GetMetaEnumItemClassConfiguration();
PrepareMetaEnumItemPropertyConfigurations(configuration);
return
configuration;
}
public
MappingConfiguration<MetaEnumItem> GetMetaEnumItemClassConfiguration()
{
var configuration =
new
MappingConfiguration<MetaEnumItem>();
configuration.MapType().Inheritance(InheritanceStrategy.Default).ToTable(SchemaMetadata +
".MetaEnumItem"
);
return
configuration;
}
public
void
PrepareMetaEnumItemPropertyConfigurations(MappingConfiguration<MetaEnumItem> configuration)
{
configuration.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Autoinc).HasFieldName(
"ModelMetadataBase._id"
).ToColumn(
"Id"
).IsNotNullable().HasColumnType(
"int"
);
configuration.HasProperty(x => x.MetaEnumId).ToColumn(
"MetaEnumId"
).IsNotNullable().HasColumnType(
"int"
);
configuration.HasProperty(x => x.Value).ToColumn(
"Value"
).IsNotNullable().HasColumnType(
"int"
);
}
1) Why in the method :
PrepareMetaEnumAssociationConfigurations
configuration.HasAssociation(m => m.MetaEnumItemList).HasConstraint().ToColumn(
"MetaEnumId"
).IsDependent();
I cant't write :
configuration.HasAssociation(m => m.MetaEnumItemList).HasConstraint((x,y)=>x.Id == y.MetaEnumId) .ToColumn("MetaEnumId").IsDependent();
==> Error 5 A property from the configured type does not take part in the expression.
2) I create a new odata service v2 :
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults =
true
)]
public
partial
class
DataContextService : OpenAccessDataService<APlus.Framework.DAL.DataContext>
{
/// <summary>
/// Initializes the service.
/// </summary>
/// <param name="config">The configuration object.</param>
public
static
void
InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule(
"*"
, EntitySetRights.All);
// TODO: Set service behavior configuration options
// Examples:
// config.DataServiceBehavior.AcceptCountRequests = true;
// config.DataServiceBehavior.AcceptProjectionRequests = true;
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
}
When i execute the service ==> The entity type 'MetaEnumItem' does not have any key properties. Please make sure the key properties are defined for this entity type.
Kind regards