This question is locked. New answers and comments are not allowed.
I'm a bit frustrated...just found out that Telerik Support does not support this product. I am struggling to understand what it is that I am doing wrong here. Hopefully somebody here can help.
I have a table OrdersWritten that has FK to OrderType. When I try inserting a new record to OrdersWritten, it keeps trying to insert a new record into OrderType.
Here is code used to add record to database.
01.
public
bool
Add(OrdersWritten info,
string
currentUserName)
02.
{
03.
try
04.
{
05.
if
(info ==
null
|| String.IsNullOrWhiteSpace(info.OrderNumber)
06.
|| String.IsNullOrWhiteSpace(currentUserName))
07.
return
false
;
08.
using
(ProductionContext db =
new
ProductionContext())
09.
{
10.
var order = db.WrittenOrders
11.
.FirstOrDefault(x => x.OrderNumber == info.OrderNumber);
12.
if
(order !=
null
)
13.
return
false
;
14.
order =
new
OrdersWritten();
15.
order.CreatedAt = DateTime.Now;
16.
order.CreatedBy = currentUserName;
17.
order.OrderNumber = info.OrderNumber;
18.
order.OrderTypeID = info.OrderTypeID;
19.
order.OrderWriter = info.OrderWriter;
20.
order.DateReceived = info.DateReceived;
21.
order.DateWritten = info.DateWritten;
22.
order.JobNum = info.JobNum;
23.
order.JobName = info.JobName;
24.
order.BatchOrders = info.BatchOrders;
25.
order.NumCabs = info.NumCabs;
26.
order.TopsFtg = info.TopsFtg;
27.
order.OutsourcedTops = info.OutsourcedTops;
28.
order.Status = 1;
29.
db.Add(order);
30.
db.SaveChanges();
31.
return
true
;
32.
}
33.
}
34.
catch
(Exception) {
throw
; }
35.
}
Here is the mapping code.
01.
private
MappingConfiguration<OrderType> GetOrderTypeConfiguration()
02.
{
03.
var mapping =
new
MappingConfiguration<OrderType>();
04.
mapping.MapType(m =>
new
{ ID = m.ID, Name = m.Name, Status = m.Status,
05.
CreatedAt = m.CreatedAt, CreatedBy = m.CreatedBy,
06.
ModifiedAt = m.ModifiedAt, ModifiedBy = m.ModifiedBy })
07.
.WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed)
08.
.ToTable(
"OrderType"
);
09.
mapping.HasProperty(u => u.ID).HasFieldName(
"id"
).IsIdentity(KeyGenerator.Autoinc);
10.
mapping.HasAssociation(x => x.WrittenOrders)
11.
.HasFieldName(
"writtenOrders"
)
12.
.WithOpposite(x => x.OrdType)
13.
.HasConstraint((x, y) => x.ID == y.OrderTypeID)
14.
.WithDataAccessKind(DataAccessKind.ReadOnly);
15.
return
mapping;
16.
}
17.
18.
private
MappingConfiguration<OrdersWritten> GetOrdersWrittenConfiguration()
19.
{
20.
var mapping =
new
MappingConfiguration<OrdersWritten>();
21.
mapping.MapType(m =>
new
{ ID = m.ID, OrderTypeID = m.OrderTypeID,
22.
OrderNumber = m.OrderNumber, OrderWriter = m.OrderWriter,
23.
DateReceived = m.DateReceived, DateWritten = m.DateWritten,
24.
JobNum = m.JobNum, JobName = m.JobName, BatchOrders = m.BatchOrders,
25.
NumCabs = m.NumCabs, TopsFtg = m.TopsFtg,
26.
OutsourcedTops = m.OutsourcedTops,
27.
Status = m.Status, CreatedAt = m.CreatedAt, CreatedBy = m.CreatedBy,
28.
ModifiedAt = m.ModifiedAt, ModifiedBy = m.ModifiedBy })
29.
.WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed)
30.
.ToTable(
"OrdersWritten"
);
31.
mapping.HasProperty(u => u.ID).HasFieldName(
"id"
)
32.
.IsIdentity(KeyGenerator.Autoinc);
33.
mapping.HasAssociation(x => x.OrdType)
34.
.HasFieldName(
"ordType"
)
35.
.WithOpposite(x => x.WrittenOrders)
36.
.ToColumn(
"OrderTypeID"
)
37.
.HasConstraint((x, y) => x.OrderTypeID == y.ID)
38.
.WithDataAccessKind(DataAccessKind.ReadOnly);
39.
return
mapping;
40.
}
I don't understand why it is trying to create a record in OrderType. What am I doing wrong?
Please help.