This question is locked. New answers and comments are not allowed.
Hi,
I've two classes A and B. A inherits from B. The class A has not nullable
fields.
I don't know to set the fields of the class A to not nullable statement in the
database by using the following mapping code:
mapping.HasProperty(o => o.XXX).IsNotNullable();
I've no problem for classes without inheritance notion.
Thank you in advance.
Kind regards.
3 Answers, 1 is accepted
0
Hello Myth,
Thank you for contacting us. I am not sure I fully understand your scenario. From the issue you describe I would guess you are using either Flat or Vertical inheritance.
If we take for example the setup above I would guess that you want the ParentField to be not nullable for the Child class and nullable for the Parent class.
Is that an accurate description of you scenario? If not, could you provide me with more details, regarding what you want to achieve? Could you tell me what kind of inheritance you are using (Flat, Vertical or Horizontal)? Could you define what kind of field you want to map as not nullable (inherited from the parent or defined in the child class)?
Thank you in advance for your cooperation. I am looking forward to your feedback.
Regards,
Simeon Simeonov
Telerik
Thank you for contacting us. I am not sure I fully understand your scenario. From the issue you describe I would guess you are using either Flat or Vertical inheritance.
class
Parent
{
public
string
ParentField {
get
;
set
; }
}
class
Child : Parent
{
public
string
ChildField {
get
;
set
; }
}
If we take for example the setup above I would guess that you want the ParentField to be not nullable for the Child class and nullable for the Parent class.
Is that an accurate description of you scenario? If not, could you provide me with more details, regarding what you want to achieve? Could you tell me what kind of inheritance you are using (Flat, Vertical or Horizontal)? Could you define what kind of field you want to map as not nullable (inherited from the parent or defined in the child class)?
Thank you in advance for your cooperation. I am looking forward to your feedback.
Regards,
Simeon Simeonov
Telerik
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
0
Myth
Top achievements
Rank 1
answered on 09 Dec 2015, 12:49 PM
Hi,
If I take your setup, we have the following mapping:
private MappingConfiguration<
Parent
> CreateMappingParent()
{
var mapping = new MappingConfiguration<
Parent
> { FieldNamingRules = { CaseMode = CaseChangeModes.CamelCase, AddPrefix = "_" } };
mapping.MapType(o => new
{
o.ParentField
}).ToTable("Parent");
mapping.HasProperty(o => o.ParentField).IsNotNullable();
return mapping;
}
private MappingConfiguration<
Child
> CreateMappingChild()
{
var mapping = new MappingConfiguration<
Child
> { FieldNamingRules = { CaseMode = CaseChangeModes.CamelCase, AddPrefix = "_" } };
mapping.MapType(o => new
{
o.ChildField
}).Inheritance(InheritanceStrategy.Vertical).ToTable(new TableName("Child", string.Empty));
mapping.HasDiscriminatorValue(typeof(Child).FullName);
mapping.HasProperty(o => o.ChildField).IsNotNullable();
return mapping;
}
The class "Parent" is defined as follows:
public class Parent
{
private string _parentField;
public string ParentField
{
get { return _parentField; }
set { _parentField = value; }
}
}
The class "Child" is defined as follows:
public class Child: Parent
{
private string _childField;
public string ChildField
{
get { return _childField; }
set { _childField = value; }
}
}
I don't have any problem with the field definition of the table "Parent":
Parent_Id int NOT NULL
voa_class varchar(255) NULL
ParentField varchar(255) NOT NULL
The field ParentField is setted with NOT NULL statement.
The problem is for the table Child. The field definition is the following:
Parent_id int NOT NULL
ChildField varchar(255) NULL
The field ChildField is setted to NULL. However, the statement "NOT NULL" is correctly defined in the class Child and the mapping. Why ?
0
Hi Myth,
Thank you for getting back to us and for the supported information. I have recreated the example implementation on my side and was able to reproduce the issue. It seems that you have stumbled upon a bug on our side. I will file a bug entry for this.
I am afraid that I cannot give you any time frame when the bug fix will be published.
In the mean time, as a work around, you can update the database by hand to not allow nullable values in the child fields and this will enforce the behavior you want.
Thank you for reporting this issue to us. I have added some Telerik points to your account as small token of recognition for reporting a new bug in our product.
Regards,
Simeon Simeonov
Telerik
Thank you for getting back to us and for the supported information. I have recreated the example implementation on my side and was able to reproduce the issue. It seems that you have stumbled upon a bug on our side. I will file a bug entry for this.
I am afraid that I cannot give you any time frame when the bug fix will be published.
In the mean time, as a work around, you can update the database by hand to not allow nullable values in the child fields and this will enforce the behavior you want.
Thank you for reporting this issue to us. I have added some Telerik points to your account as small token of recognition for reporting a new bug in our product.
Regards,
Simeon Simeonov
Telerik
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.