This question is locked. New answers and comments are not allowed.
Hi,
I'm using DataAccess to generate artificial tables at runtime (see code snippet below). As I understood, artificial types are compiled in memory so artificial types are just "normal" classes. Is it possible to define either a base type or at least an interface for an artifical type? What does the extension method .HasBaseType() exactly do?
For example my artifical types always have: Id, CreatedAt, ModifiedAt, CreatedBy, ModifiedBy. It would be very helpful if I could cast query results directly into an Interface such as IDataItem. Is there a way to do that?
Thanks for your feedback!
Chris
I'm using DataAccess to generate artificial tables at runtime (see code snippet below). As I understood, artificial types are compiled in memory so artificial types are just "normal" classes. Is it possible to define either a base type or at least an interface for an artifical type? What does the extension method .HasBaseType() exactly do?
For example my artifical types always have: Id, CreatedAt, ModifiedAt, CreatedBy, ModifiedBy. It would be very helpful if I could cast query results directly into an Interface such as IDataItem. Is there a way to do that?
public
interface
IDataItem
{
int
Id {
get
;
set
; }
DateTime? CreatedAt {
get
;
set
; }
DateTime? ModifiedAt {
get
;
set
; }
String CreatedBy {
get
;
set
; }
String ModifiedBy {
get
;
set
; }
}
01.
MappingConfiguration mc =
new
MappingConfiguration(
"Spyder"
,
"Inventox.Core.Data"
);
02.
mc.FieldNamingRules.CaseMode = CaseChangeModes.Unchanged;
03.
mc.MapType().WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed).ToTable(
"Spyder"
);
04.
mc.HasArtificialIdentity<
int
>(KeyGenerator.Autoinc).HasFieldName(
"Id"
).WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn(
"Id"
).IsNotNullable().HasColumnType(
"int"
).HasPrecision(0).HasScale(0);
05.
mc.HasArtificialStringProperty(
"Title"
).WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn(
"Title"
).IsNullable().HasColumnType(
"nvarchar"
).HasLength(128);
06.
mc.HasArtificialDateTimeProperty(
"CreatedAt"
).WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn(
"CreatedAt"
).IsNullable().HasColumnType(
"datetime"
);
07.
mc.HasArtificialStringProperty(
"CreatedBy"
).WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn(
"CreatedBy"
).IsNullable().HasColumnType(
"nvarchar"
).HasLength(100);
08.
mc.HasArtificialDateTimeProperty(
"ModifiedAt"
).WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn(
"ModifiedAt"
).IsNullable().HasColumnType(
"datetime"
);
09.
mc.HasArtificialStringProperty(
"ModifiedBy"
).WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn(
"ModifiedBy"
).IsNullable().HasColumnType(
"nvarchar"
).HasLength(100);
10.
mappingConfigurations.Add(mc);
Thanks for your feedback!
Chris