This question is locked. New answers and comments are not allowed.
Hi,
I'm currently trying to persist a linked list of polymorphic objects.I chain those objects by using an interface.
Two questions have come up:
1) I wrote an extension method for making the possible types for IJob NextJob known to all classes.
Is there this bad in any way or is there a better way to do this? I wanted to reduce the .WithAvailable() clutter which i otherwise had to maintain multiple times on every single class mapping that implements IJob
2) Is it correct that interface references are completely unmanaged and .IsManaged() on the association has no effect?
The only way to persist a linked list is by saving every single item of the list and doing the linking afterwards.
Everything else results in exceptions.
Regards
Joe
I'm currently trying to persist a linked list of polymorphic objects.I chain those objects by using an interface.
public interface IJob{ int Id { get; set; } IJob NextJob { get; set; }}public class CopyJob : IJob{ public int Id { get; set; } public IJob NextJob { get; set; }}public class ProcessJob : IJob{ public int Id { get; set; } public IJob NextJob { get; set; }}Two questions have come up:
1) I wrote an extension method for making the possible types for IJob NextJob known to all classes.
Is there this bad in any way or is there a better way to do this? I wanted to reduce the .WithAvailable() clutter which i otherwise had to maintain multiple times on every single class mapping that implements IJob
public static NavigationPropertyConfiguration<TEntity, TInverse> WithIJobMapping<TEntity, TInverse>(this NavigationPropertyConfiguration<TEntity, TInverse> config){ return config.WithAvailable(typeof(CopyJob), "CopyJob") .WithAvailable(typeof(ProcessJob), "ProcessJob") .WithDiscriminatingColumn("Type") .ToColumn("JobId").IsManaged();}
var copyJobMap = new MappingConfiguration<CopyJob>();
copyJobMap.MapType().WithConcurencyControl(OptimisticConcurrencyControlStrategy.None);
copyJobMap.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Autoinc);
copyJobMap.HasAssociation(x => x.NextJob).WithIJobMapping();2) Is it correct that interface references are completely unmanaged and .IsManaged() on the association has no effect?
The only way to persist a linked list is by saving every single item of the list and doing the linking afterwards.
Everything else results in exceptions.
CopyJob copyJob = new CopyJob();_dbContext.Add(copyJob);_dbContext.SaveChanges();ProcessJob processJob = new ProcessJob();_dbContext.Add(processJob);_dbContext.SaveChanges();copyJob.NextJob = processJob;_dbContext.SaveChanges();Regards
Joe