@@ -1,82 +1,82 @@
using System.IO;
using System.Text;
using System.Xml.Linq;
using System.Xml.Serialization;
using JPB.DataAccess.AdoWrapper;
using JPB.DataAccess.DbInfoConfig;
using JPB.DataAccess.Tests.TestModels.XmlDataRecordTest;
using NUnit.Framework;

namespace JPB.DataAccess.Tests.XmlDataRecordTests
#if MsSql
.MsSQL
#endif

#if SqLite
.SqLite
#endif
{
[TestFixture]
public class XmlDataRecordTest
{
[Test]
public void GetName()
{
var xmlSerilizer = new XmlSerializer(typeof (InstanceMock));
string content = "";
using (var ms = new MemoryStream())
{
xmlSerilizer.Serialize(ms, new InstanceMock());
content = Encoding.Default.GetString(ms.ToArray());
}

var xmlRecord = new XmlDataRecord(content, typeof (InstanceMock).GetClassInfo());
Assert.AreEqual(xmlRecord.GetName(0), "MockPropA");
Assert.AreEqual(xmlRecord.GetName(1), "MockPropB");
}

[Test]
public void GetValue()
{
var xmlSerilizer = new XmlSerializer(typeof (InstanceMock));
string content = "";
using (var ms = new MemoryStream())
{
xmlSerilizer.Serialize(ms, new InstanceMock());
content = Encoding.Default.GetString(ms.ToArray());
}

var xmlRecord = new XmlDataRecord(content, typeof (InstanceMock).GetClassInfo());
Assert.AreEqual(xmlRecord.GetValue(0), "NAN");
Assert.AreEqual(xmlRecord.GetValue(1), 0);
}

[Test]
public void InstanceFromString()
{
var xmlSerilizer = new XmlSerializer(typeof (InstanceMock));
string content = "";
using (var ms = new MemoryStream())
{
xmlSerilizer.Serialize(ms, new InstanceMock());
content = Encoding.Default.GetString(ms.ToArray());
}

new XmlDataRecord(content, typeof (InstanceMock).GetClassInfo());
}

[Test]
public void InstanceFromXDocument()
{
var xmlSerilizer = new XmlSerializer(typeof (InstanceMock));
string content = "";
using (var ms = new MemoryStream())
{
xmlSerilizer.Serialize(ms, new InstanceMock());
content = Encoding.Default.GetString(ms.ToArray());
}

new XmlDataRecord(XDocument.Parse(content), typeof (InstanceMock));
}
}
using System.IO;
using System.Text;
using System.Xml.Linq;
using System.Xml.Serialization;
using JPB.DataAccess.AdoWrapper;
using JPB.DataAccess.DbInfoConfig;
using JPB.DataAccess.Tests.TestModels.XmlDataRecordTest;
using NUnit.Framework;

namespace JPB.DataAccess.Tests.XmlDataRecordTests
#if MsSql
.MsSQL
#endif

#if SqLite
.SqLite
#endif
{
[TestFixture]
public class XmlDataRecordTest
{
[Test]
public void GetName()
{
var xmlSerilizer = new XmlSerializer(typeof (InstanceMock));
string content = "";
using (var ms = new MemoryStream())
{
xmlSerilizer.Serialize(ms, new InstanceMock());
content = Encoding.Default.GetString(ms.ToArray());
}

var xmlRecord = new XmlDataRecord(content, typeof (InstanceMock).GetClassInfo());
Assert.AreEqual(xmlRecord.GetName(0), "MockPropA");
Assert.AreEqual(xmlRecord.GetName(1), "MockPropB");
}

[Test]
public void GetValue()
{
var xmlSerilizer = new XmlSerializer(typeof (InstanceMock));
string content = "";
using (var ms = new MemoryStream())
{
xmlSerilizer.Serialize(ms, new InstanceMock());
content = Encoding.Default.GetString(ms.ToArray());
}

var xmlRecord = new XmlDataRecord(content, typeof (InstanceMock).GetClassInfo());
Assert.AreEqual(xmlRecord.GetValue(0), "NAN");
Assert.AreEqual(xmlRecord.GetValue(1), 0);
}

[Test]
public void InstanceFromString()
{
var xmlSerilizer = new XmlSerializer(typeof (InstanceMock));
string content = "";
using (var ms = new MemoryStream())
{
xmlSerilizer.Serialize(ms, new InstanceMock());
content = Encoding.Default.GetString(ms.ToArray());
}

new XmlDataRecord(content, typeof (InstanceMock).GetClassInfo());
}

[Test]
public void InstanceFromXDocument()
{
var xmlSerilizer = new XmlSerializer(typeof (InstanceMock));
string content = "";
using (var ms = new MemoryStream())
{
xmlSerilizer.Serialize(ms, new InstanceMock());
content = Encoding.Default.GetString(ms.ToArray());
}

new XmlDataRecord(XDocument.Parse(content), typeof (InstanceMock));
}
}
}

Large diffs are not rendered by default.

@@ -1,76 +1,76 @@
/*
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
Please consider to give some Feedback on CodeProject
http://www.codeproject.com/Articles/818690/Yet-Another-ORM-ADO-NET-Wrapper
*/

using System;
using System.Collections.Generic;

namespace JPB.DataAccess.Contacts.MetaApi
{
/// <summary>
///
/// </summary>
/// <typeparam name="TProp"></typeparam>
/// <typeparam name="TAttr"></typeparam>
/// <typeparam name="TMeth"></typeparam>
/// <typeparam name="TCtor"></typeparam>
/// <typeparam name="TArg"></typeparam>
public interface IClassInfoCache<TProp, TAttr, TMeth, TCtor, TArg> : IClassInfoCache
where TProp : class, IPropertyInfoCache<TAttr>, new()
where TAttr : class, IAttributeInfoCache, new()
where TMeth : class, IMethodInfoCache<TAttr, TArg>, new()
where TCtor : class, IConstructorInfoCache<TAttr, TArg>, new()
where TArg : class, IMethodArgsInfoCache<TAttr>, new()
{
/// <summary>
///
/// </summary>
/// <param name="type"></param>
/// <param name="anon"></param>
/// <returns></returns>
IClassInfoCache<TProp, TAttr, TMeth, TCtor, TArg> Init(Type type, bool anon = false);

/// <summary>
/// All Propertys
/// </summary>
Dictionary<string, TProp> Propertys { get; }

/// <summary>
/// All Attributes on class level
/// </summary>
HashSet<TAttr> Attributes { get; }

/// <summary>
/// All Mehtods
/// </summary>
HashSet<TMeth> Mehtods { get; }

/// <summary>
/// All Constructors
/// </summary>
HashSet<TCtor> Constructors { get; }
}

/// <summary>
/// Defines the most basic infos about an class
/// </summary>
public interface IClassInfoCache : IEquatable<IClassInfoCache>,
IComparable<IClassInfoCache>,
IEquatable<Type>
{
/// <summary>
/// The .net ClassName
/// </summary>
string ClassName { get; }

/// <summary>
/// The .net Type instance
/// </summary>
Type Type { get; }
}
/*
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
Please consider to give some Feedback on CodeProject
http://www.codeproject.com/Articles/818690/Yet-Another-ORM-ADO-NET-Wrapper
*/

using System;
using System.Collections.Generic;

namespace JPB.DataAccess.Contacts.MetaApi
{
/// <summary>
///
/// </summary>
/// <typeparam name="TProp"></typeparam>
/// <typeparam name="TAttr"></typeparam>
/// <typeparam name="TMeth"></typeparam>
/// <typeparam name="TCtor"></typeparam>
/// <typeparam name="TArg"></typeparam>
public interface IClassInfoCache<TProp, TAttr, TMeth, TCtor, TArg> : IClassInfoCache
where TProp : class, IPropertyInfoCache<TAttr>, new()
where TAttr : class, IAttributeInfoCache, new()
where TMeth : class, IMethodInfoCache<TAttr, TArg>, new()
where TCtor : class, IConstructorInfoCache<TAttr, TArg>, new()
where TArg : class, IMethodArgsInfoCache<TAttr>, new()
{
/// <summary>
///
/// </summary>
/// <param name="type"></param>
/// <param name="anon"></param>
/// <returns></returns>
IClassInfoCache<TProp, TAttr, TMeth, TCtor, TArg> Init(Type type, bool anon = false);

/// <summary>
/// All Propertys
/// </summary>
Dictionary<string, TProp> Propertys { get; }

/// <summary>
/// All Attributes on class level
/// </summary>
HashSet<TAttr> Attributes { get; }

/// <summary>
/// All Mehtods
/// </summary>
HashSet<TMeth> Mehtods { get; }

/// <summary>
/// All Constructors
/// </summary>
HashSet<TCtor> Constructors { get; }
}

/// <summary>
/// Defines the most basic infos about an class
/// </summary>
public interface IClassInfoCache : IEquatable<IClassInfoCache>,
IComparable<IClassInfoCache>,
IEquatable<Type>
{
/// <summary>
/// The .net ClassName
/// </summary>
string ClassName { get; }

/// <summary>
/// The .net Type instance
/// </summary>
Type Type { get; }
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -1,179 +1,179 @@
/*
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
Please consider to give some Feedback on CodeProject
http://www.codeproject.com/Articles/818690/Yet-Another-ORM-ADO-NET-Wrapper
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using JPB.DataAccess.MetaApi.Model;
using JPB.DataAccess.ModelsAnotations;

namespace JPB.DataAccess.DbInfoConfig.DbInfo
{
internal class DbPropertyInfoCache<T, TE> : DbPropertyInfoCache
{
internal DbPropertyInfoCache(string name, Action<T, TE> setter = null, Func<T, TE> getter = null,
params AttributeInfoCache[] attributes)
{
if (attributes == null)
throw new ArgumentNullException("attributes");

PropertyName = name;

if (setter != null)
{
Setter = new MethodInfoCache<DbAttributeInfoCache, MethodArgsInfoCache<DbAttributeInfoCache>>((o, objects) =>
{
setter((T)o, (TE)objects[0]);
return null;
});
}

if (getter != null)
{
Getter = new MethodInfoCache<DbAttributeInfoCache, MethodArgsInfoCache<DbAttributeInfoCache>>((o, objects) => getter((T)o));
}
}
}

/// <summary>
/// Infos about the Property
/// </summary>
public class DbPropertyInfoCache : PropertyInfoCache<DbAttributeInfoCache>
{
#if !DEBUG
[DebuggerHidden]
#endif
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public DbPropertyInfoCache()
{
base.Attributes = new HashSet<DbAttributeInfoCache>();
}

/// <summary>
/// </summary>
internal DbPropertyInfoCache(PropertyInfo propertyInfo, bool anon)
: base(propertyInfo, anon)
{
if (propertyInfo != null)
{
Refresh();
}
}

//internal DbPropertyInfoCache(string dbName, string propertyName, Type propertyType)
//{
// this.PropertyName = propertyName;
// if (dbName != propertyName)
// {
// this.Attributes.Add(new DbAttributeInfoCache<ForModelAttribute>(new AttributeInfoCache(new ForModelAttribute(dbName))));
// }
//}

/// <summary>
/// The class that owns this Property
/// </summary>
public DbClassInfoCache DeclaringClass { get; protected internal set; }

/// <summary>
/// if known the ForModelAttribute attribute
/// </summary>
public DbAttributeInfoCache<ForModelAttribute> ForModelAttribute { get; protected internal set; }

/// <summary>
/// if known the ForXml attribute
/// </summary>
public DbAttributeInfoCache<FromXmlAttribute> FromXmlAttribute { get; protected internal set; }

/// <summary>
/// if known the ForXml attribute
/// </summary>
public DbAttributeInfoCache<ForeignKeyDeclarationAttribute> ForginKeyDeclarationAttribute { get; protected internal set; }

/// <summary>
/// Should this property not be inserterd
/// </summary>
public bool InsertIgnore { get; protected internal set; }

/// <summary>
/// if known the ForginKey attribute
/// </summary>
public DbAttributeInfoCache<ForeignKeyAttribute> ForginKeyAttribute { get; protected internal set; }

/// <summary>
/// Returns the For Model name if known or the Propertyname
/// </summary>
public string DbName
{
get
{
if (ForModelAttribute != null)
return ForModelAttribute.Attribute.AlternatingName;

if (FromXmlAttribute != null)
return FromXmlAttribute.Attribute.FieldName;
return PropertyName;
}
}

/// <summary>
/// if known the RowVersion Attribute
/// </summary>
public DbAttributeInfoCache<RowVersionAttribute> RowVersionAttribute { get; private set; }

/// <summary>
/// if knwon the PrimaryKey Attribute
/// </summary>
public DbAttributeInfoCache<PrimaryKeyAttribute> PrimaryKeyAttribute { get; private set; }

/// <summary>
/// if knwon the Ignore Reflection Attribute
/// </summary>
public DbAttributeInfoCache<IgnoreReflectionAttribute> IgnoreAnyAttribute { get; private set; }

/// <summary>
/// For internal Usage only
/// </summary>
public void Refresh()
{
PrimaryKeyAttribute = DbAttributeInfoCache<PrimaryKeyAttribute>.WrapperOrNull(Attributes.FirstOrDefault(f => f.Attribute.GetType() == typeof(PrimaryKeyAttribute)));
InsertIgnore = Attributes.Any(f => f.Attribute is InsertIgnoreAttribute);
if (Getter != null && Getter.MethodInfo != null)
{
if (Getter.MethodInfo.IsVirtual)
{
ForginKeyAttribute =
DbAttributeInfoCache<ForeignKeyAttribute>.WrapperOrNull(
Attributes.FirstOrDefault(f => f.Attribute.GetType() == typeof(ForeignKeyAttribute)));
}
else
{
ForginKeyAttribute = null;
}
}
RowVersionAttribute =
DbAttributeInfoCache<RowVersionAttribute>.WrapperOrNull(
Attributes.FirstOrDefault(s => s.Attribute is RowVersionAttribute));
FromXmlAttribute = DbAttributeInfoCache<FromXmlAttribute>.WrapperOrNull(Attributes.FirstOrDefault(f => f.Attribute.GetType() == typeof(FromXmlAttribute)));
ForModelAttribute = DbAttributeInfoCache<ForModelAttribute>.WrapperOrNull(Attributes.FirstOrDefault(f => f.Attribute.GetType() == typeof(ForModelAttribute)));
IgnoreAnyAttribute = DbAttributeInfoCache<IgnoreReflectionAttribute>.WrapperOrNull(Attributes.FirstOrDefault(f => f.Attribute.GetType() == typeof(IgnoreReflectionAttribute)));
ForginKeyDeclarationAttribute = DbAttributeInfoCache<ForeignKeyDeclarationAttribute>.WrapperOrNull(Attributes.FirstOrDefault(f => f.Attribute.GetType() == typeof(ForeignKeyDeclarationAttribute)));
}

//internal static PropertyInfoCache Logical(string info)
//{
// return new PropertyInfoCache(null)
// {
// PropertyName = info
// };
//}
}
/*
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
Please consider to give some Feedback on CodeProject
http://www.codeproject.com/Articles/818690/Yet-Another-ORM-ADO-NET-Wrapper
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using JPB.DataAccess.MetaApi.Model;
using JPB.DataAccess.ModelsAnotations;

namespace JPB.DataAccess.DbInfoConfig.DbInfo
{
internal class DbPropertyInfoCache<T, TE> : DbPropertyInfoCache
{
internal DbPropertyInfoCache(string name, Action<T, TE> setter = null, Func<T, TE> getter = null,
params AttributeInfoCache[] attributes)
{
if (attributes == null)
throw new ArgumentNullException("attributes");

PropertyName = name;

if (setter != null)
{
Setter = new MethodInfoCache<DbAttributeInfoCache, MethodArgsInfoCache<DbAttributeInfoCache>>((o, objects) =>
{
setter((T)o, (TE)objects[0]);
return null;
});
}

if (getter != null)
{
Getter = new MethodInfoCache<DbAttributeInfoCache, MethodArgsInfoCache<DbAttributeInfoCache>>((o, objects) => getter((T)o));
}
}
}

/// <summary>
/// Infos about the Property
/// </summary>
public class DbPropertyInfoCache : PropertyInfoCache<DbAttributeInfoCache>
{
#if !DEBUG
[DebuggerHidden]
#endif
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public DbPropertyInfoCache()
{
base.Attributes = new HashSet<DbAttributeInfoCache>();
}

/// <summary>
/// </summary>
internal DbPropertyInfoCache(PropertyInfo propertyInfo, bool anon)
: base(propertyInfo, anon)
{
if (propertyInfo != null)
{
Refresh();
}
}

//internal DbPropertyInfoCache(string dbName, string propertyName, Type propertyType)
//{
// this.PropertyName = propertyName;
// if (dbName != propertyName)
// {
// this.Attributes.Add(new DbAttributeInfoCache<ForModelAttribute>(new AttributeInfoCache(new ForModelAttribute(dbName))));
// }
//}

/// <summary>
/// The class that owns this Property
/// </summary>
public DbClassInfoCache DeclaringClass { get; protected internal set; }

/// <summary>
/// if known the ForModelAttribute attribute
/// </summary>
public DbAttributeInfoCache<ForModelAttribute> ForModelAttribute { get; protected internal set; }

/// <summary>
/// if known the ForXml attribute
/// </summary>
public DbAttributeInfoCache<FromXmlAttribute> FromXmlAttribute { get; protected internal set; }

/// <summary>
/// if known the ForXml attribute
/// </summary>
public DbAttributeInfoCache<ForeignKeyDeclarationAttribute> ForginKeyDeclarationAttribute { get; protected internal set; }

/// <summary>
/// Should this property not be inserterd
/// </summary>
public bool InsertIgnore { get; protected internal set; }

/// <summary>
/// if known the ForginKey attribute
/// </summary>
public DbAttributeInfoCache<ForeignKeyAttribute> ForginKeyAttribute { get; protected internal set; }

/// <summary>
/// Returns the For Model name if known or the Propertyname
/// </summary>
public string DbName
{
get
{
if (ForModelAttribute != null)
return ForModelAttribute.Attribute.AlternatingName;

if (FromXmlAttribute != null)
return FromXmlAttribute.Attribute.FieldName;
return PropertyName;
}
}

/// <summary>
/// if known the RowVersion Attribute
/// </summary>
public DbAttributeInfoCache<RowVersionAttribute> RowVersionAttribute { get; private set; }

/// <summary>
/// if knwon the PrimaryKey Attribute
/// </summary>
public DbAttributeInfoCache<PrimaryKeyAttribute> PrimaryKeyAttribute { get; private set; }

/// <summary>
/// if knwon the Ignore Reflection Attribute
/// </summary>
public DbAttributeInfoCache<IgnoreReflectionAttribute> IgnoreAnyAttribute { get; private set; }

/// <summary>
/// For internal Usage only
/// </summary>
public void Refresh()
{
PrimaryKeyAttribute = DbAttributeInfoCache<PrimaryKeyAttribute>.WrapperOrNull(Attributes.FirstOrDefault(f => f.Attribute.GetType() == typeof(PrimaryKeyAttribute)));
InsertIgnore = Attributes.Any(f => f.Attribute is InsertIgnoreAttribute);
if (Getter != null && Getter.MethodInfo != null)
{
if (Getter.MethodInfo.IsVirtual)
{
ForginKeyAttribute =
DbAttributeInfoCache<ForeignKeyAttribute>.WrapperOrNull(
Attributes.FirstOrDefault(f => f.Attribute.GetType() == typeof(ForeignKeyAttribute)));
}
else
{
ForginKeyAttribute = null;
}
}
RowVersionAttribute =
DbAttributeInfoCache<RowVersionAttribute>.WrapperOrNull(
Attributes.FirstOrDefault(s => s.Attribute is RowVersionAttribute));
FromXmlAttribute = DbAttributeInfoCache<FromXmlAttribute>.WrapperOrNull(Attributes.FirstOrDefault(f => f.Attribute.GetType() == typeof(FromXmlAttribute)));
ForModelAttribute = DbAttributeInfoCache<ForModelAttribute>.WrapperOrNull(Attributes.FirstOrDefault(f => f.Attribute.GetType() == typeof(ForModelAttribute)));
IgnoreAnyAttribute = DbAttributeInfoCache<IgnoreReflectionAttribute>.WrapperOrNull(Attributes.FirstOrDefault(f => f.Attribute.GetType() == typeof(IgnoreReflectionAttribute)));
ForginKeyDeclarationAttribute = DbAttributeInfoCache<ForeignKeyDeclarationAttribute>.WrapperOrNull(Attributes.FirstOrDefault(f => f.Attribute.GetType() == typeof(ForeignKeyDeclarationAttribute)));
}

//internal static PropertyInfoCache Logical(string info)
//{
// return new PropertyInfoCache(null)
// {
// PropertyName = info
// };
//}
}
}

Large diffs are not rendered by default.

@@ -1,53 +1,53 @@
/*
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
Please consider to give some Feedback on CodeProject
http://www.codeproject.com/Articles/818690/Yet-Another-ORM-ADO-NET-Wrapper
*/
using System;
using System.Data;
using JPB.DataAccess.Contacts;
using JPB.DataAccess.DbInfoConfig;
using JPB.DataAccess.DbInfoConfig.DbInfo;
using JPB.DataAccess.ModelsAnotations;

namespace JPB.DataAccess.Manager
{
partial class DbAccessLayer
{
/// <summary>
/// Creates and Executes a Standart SQL delete statement based on the Entry
/// </summary>
/// <typeparam name="T"></typeparam>
public void Delete<T>(T entry)
{
var deleteCommand = CreateDeleteQueryFactory(entry.GetType().GetClassInfo(), entry, Database);
RaiseDelete(entry, deleteCommand, Database);
Database.Run(s => { s.ExecuteNonQuery(deleteCommand); });
}

internal IDbCommand _CreateDelete(DbClassInfoCache classInfo, object entry, IDatabase db)
{
if (classInfo.PrimaryKeyProperty == null)
throw new NotSupportedException(string.Format("No Primary key on '{0}' was supplyed. Operation is not supported", classInfo.ClassName));

var proppk = classInfo.PrimaryKeyProperty.DbName;
var query = "DELETE FROM " + classInfo.TableName + " WHERE " + proppk + " = @0";
return db.CreateCommandWithParameterValues(query, new Tuple<Type, object>(classInfo.PrimaryKeyProperty.PropertyType, classInfo.PrimaryKeyProperty.Getter.Invoke(entry)));
}

/// <summary>
/// Creates and Executes a Standart SQL delete statement based on the Entry
/// uses factory Mehtod if availbile
/// </summary>
/// <typeparam name="T"></typeparam>
public void Delete<T>(T entry, IDatabase db, params object[] parameter)
{
var deleteCommand = CreateDeleteQueryFactory(entry.GetType().GetClassInfo(), entry, db, parameter);
RaiseDelete(entry, deleteCommand, db);
db.Run(s => { s.ExecuteNonQuery(deleteCommand); });
}
}
/*
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
Please consider to give some Feedback on CodeProject
http://www.codeproject.com/Articles/818690/Yet-Another-ORM-ADO-NET-Wrapper
*/
using System;
using System.Data;
using JPB.DataAccess.Contacts;
using JPB.DataAccess.DbInfoConfig;
using JPB.DataAccess.DbInfoConfig.DbInfo;
using JPB.DataAccess.ModelsAnotations;

namespace JPB.DataAccess.Manager
{
partial class DbAccessLayer
{
/// <summary>
/// Creates and Executes a Standart SQL delete statement based on the Entry
/// </summary>
/// <typeparam name="T"></typeparam>
public void Delete<T>(T entry)
{
var deleteCommand = CreateDeleteQueryFactory(entry.GetType().GetClassInfo(), entry, Database);
RaiseDelete(entry, deleteCommand, Database);
Database.Run(s => { s.ExecuteNonQuery(deleteCommand); });
}

internal IDbCommand _CreateDelete(DbClassInfoCache classInfo, object entry, IDatabase db)
{
if (classInfo.PrimaryKeyProperty == null)
throw new NotSupportedException(string.Format("No Primary key on '{0}' was supplyed. Operation is not supported", classInfo.ClassName));

var proppk = classInfo.PrimaryKeyProperty.DbName;
var query = "DELETE FROM " + classInfo.TableName + " WHERE " + proppk + " = @0";
return db.CreateCommandWithParameterValues(query, new Tuple<Type, object>(classInfo.PrimaryKeyProperty.PropertyType, classInfo.PrimaryKeyProperty.Getter.Invoke(entry)));
}

/// <summary>
/// Creates and Executes a Standart SQL delete statement based on the Entry
/// uses factory Mehtod if availbile
/// </summary>
/// <typeparam name="T"></typeparam>
public void Delete<T>(T entry, IDatabase db, params object[] parameter)
{
var deleteCommand = CreateDeleteQueryFactory(entry.GetType().GetClassInfo(), entry, db, parameter);
RaiseDelete(entry, deleteCommand, db);
db.Run(s => { s.ExecuteNonQuery(deleteCommand); });
}
}
}

Large diffs are not rendered by default.

@@ -1,53 +1,53 @@
/*
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
Please consider to give some Feedback on CodeProject
http://www.codeproject.com/Articles/818690/Yet-Another-ORM-ADO-NET-Wrapper
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using JPB.DataAccess.DbInfoConfig;

namespace JPB.DataAccess.Manager
{
public partial class DbAccessLayer
{
/// <summary>
/// Validates a Entity
/// </summary>
/// <exception cref="ValidationException"></exception>
public static void ValidateEntity(object instance)
{
var context = new ValidationContext(instance);
Validator.ValidateObject(instance, context, false);
}

/// <summary>
/// Validates a Entity
/// </summary>
/// <exception cref="ValidationException"></exception>
public static void ValidateEntityPk(object instance)
{
var pkProperty = instance.GetType().GetClassInfo().PrimaryKeyProperty.PropertyName;
var context = new ValidationContext(instance);
context.MemberName = pkProperty;
Validator.ValidateProperty(instance, context);
}

/// <summary>
/// Validates a Entity
/// </summary>
/// <exception cref="ValidationException"></exception>
public static Tuple<bool, ICollection<ValidationResult>> TryValidateEntity(object instance)
{
var context = new ValidationContext(instance);
var result = new Collection<ValidationResult>();
var success = Validator.TryValidateObject(instance, context, result);
return new Tuple<bool, ICollection<ValidationResult>>(success, result);
}
}
/*
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
Please consider to give some Feedback on CodeProject
http://www.codeproject.com/Articles/818690/Yet-Another-ORM-ADO-NET-Wrapper
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using JPB.DataAccess.DbInfoConfig;

namespace JPB.DataAccess.Manager
{
public partial class DbAccessLayer
{
/// <summary>
/// Validates a Entity
/// </summary>
/// <exception cref="ValidationException"></exception>
public static void ValidateEntity(object instance)
{
var context = new ValidationContext(instance);
Validator.ValidateObject(instance, context, false);
}

/// <summary>
/// Validates a Entity
/// </summary>
/// <exception cref="ValidationException"></exception>
public static void ValidateEntityPk(object instance)
{
var pkProperty = instance.GetType().GetClassInfo().PrimaryKeyProperty.PropertyName;
var context = new ValidationContext(instance);
context.MemberName = pkProperty;
Validator.ValidateProperty(instance, context);
}

/// <summary>
/// Validates a Entity
/// </summary>
/// <exception cref="ValidationException"></exception>
public static Tuple<bool, ICollection<ValidationResult>> TryValidateEntity(object instance)
{
var context = new ValidationContext(instance);
var result = new Collection<ValidationResult>();
var success = Validator.TryValidateObject(instance, context, result);
return new Tuple<bool, ICollection<ValidationResult>>(success, result);
}
}
}
@@ -1,68 +1,68 @@
/*
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
Please consider to give some Feedback on CodeProject
http://www.codeproject.com/Articles/818690/Yet-Another-ORM-ADO-NET-Wrapper
*/

using System;
using System.Collections.Generic;
using JPB.DataAccess.Contacts.MetaApi;

namespace JPB.DataAccess.MetaApi.Model.Equatable
{
internal class ClassInfoEquatableComparer
: IEqualityComparer<IClassInfoCache>,
IEqualityComparer<Type>,
IComparer<IClassInfoCache>
{
public bool Equals(IClassInfoCache x, IClassInfoCache y)
{
if (x == null && y == null)
return true;
if (x == null || y == null)
return false;
if (x.ClassName != y.ClassName)
return false;
if (x.Type == y.Type)
return true;
return true;
}

public int GetHashCode(IClassInfoCache obj)
{
return GetHashCode(obj.Type);
}

public int Compare(IClassInfoCache x, IClassInfoCache y)
{
if (x == null)
return -1;
if (y == null)
return +1;
return System.String.Compare(x.ClassName, y.ClassName, System.StringComparison.Ordinal);
}

public bool Equals(Type x, Type y)
{
if (x == null && y == null)
return true;
if (x == null || y == null)
return false;
if (x.FullName != y.FullName)
return false;
if (x == y)
return true;
if (x.IsEquivalentTo(y))
return true;
return false;
}

public int GetHashCode(Type obj)
{
return obj.GetHashCode();
}
}
/*
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
Please consider to give some Feedback on CodeProject
http://www.codeproject.com/Articles/818690/Yet-Another-ORM-ADO-NET-Wrapper
*/

using System;
using System.Collections.Generic;
using JPB.DataAccess.Contacts.MetaApi;

namespace JPB.DataAccess.MetaApi.Model.Equatable
{
internal class ClassInfoEquatableComparer
: IEqualityComparer<IClassInfoCache>,
IEqualityComparer<Type>,
IComparer<IClassInfoCache>
{
public bool Equals(IClassInfoCache x, IClassInfoCache y)
{
if (x == null && y == null)
return true;
if (x == null || y == null)
return false;
if (x.ClassName != y.ClassName)
return false;
if (x.Type == y.Type)
return true;
return true;
}

public int GetHashCode(IClassInfoCache obj)
{
return GetHashCode(obj.Type);
}

public int Compare(IClassInfoCache x, IClassInfoCache y)
{
if (x == null)
return -1;
if (y == null)
return +1;
return System.String.Compare(x.ClassName, y.ClassName, System.StringComparison.Ordinal);
}

public bool Equals(Type x, Type y)
{
if (x == null && y == null)
return true;
if (x == null || y == null)
return false;
if (x.FullName != y.FullName)
return false;
if (x == y)
return true;
if (x.IsEquivalentTo(y))
return true;
return false;
}

public int GetHashCode(Type obj)
{
return obj.GetHashCode();
}
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -1,110 +1,110 @@
/*
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
Please consider to give some Feedback on CodeProject
http://www.codeproject.com/Articles/818690/Yet-Another-ORM-ADO-NET-Wrapper
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using JPB.DataAccess.DbInfoConfig;
using JPB.DataAccess.Query.Contracts;

namespace JPB.DataAccess.Query
{
internal class QueryEagerEnumerator : IEnumerator, IDisposable
{
private readonly ArrayList _elements;
private readonly IQueryContainer _queryContainer;
private readonly Type _type;
private int _counter;
private List<IDataRecord> _enumerateDataRecords;
private Task _task;

internal QueryEagerEnumerator(IQueryContainer queryContainer, Type type)
{
_queryContainer = queryContainer;
_type = type;
_elements = new ArrayList();
_counter = 0;
Load();
}

public bool MoveNext()
{
_task.Wait();

try
{
_counter++;

if (_elements.Count >= _counter)
{
Current = _elements[_counter];
return true;
}

if (_enumerateDataRecords.Count < _counter)
return false;

var dataRecord = _enumerateDataRecords.ElementAt(_counter - 1);
Current = _queryContainer.AccessLayer.SetPropertysViaReflection(_type.GetClassInfo(), dataRecord);
_elements.Add(Current);

return true;
}
catch (Exception)
{
return false;
}
}

public void Reset()
{
_counter = 0;
}

public object Current { get; private set; }

/// <summary>
/// Mehtod for async loading this will bring us some m secs
/// </summary>
private void Load()
{
_task = new Task(() =>
{
var query = _queryContainer.Compile();
_enumerateDataRecords = _queryContainer.AccessLayer.EnumerateDataRecords(query, true);
});
_task.Start();
}

public void Dispose()
{
if (_task != null)
_task.Dispose();
if (_enumerateDataRecords != null)
_enumerateDataRecords.Clear();
_elements.Clear();
}
}

internal class QueryEagerEnumerator<T> : QueryEagerEnumerator, IEnumerator<T>
{
internal QueryEagerEnumerator(IQueryContainer queryContainer, Type type)
: base(queryContainer, type)
{
}

public new T Current
{
get { return (T)base.Current; }
}
}
/*
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
Please consider to give some Feedback on CodeProject
http://www.codeproject.com/Articles/818690/Yet-Another-ORM-ADO-NET-Wrapper
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using JPB.DataAccess.DbInfoConfig;
using JPB.DataAccess.Query.Contracts;

namespace JPB.DataAccess.Query
{
internal class QueryEagerEnumerator : IEnumerator, IDisposable
{
private readonly ArrayList _elements;
private readonly IQueryContainer _queryContainer;
private readonly Type _type;
private int _counter;
private List<IDataRecord> _enumerateDataRecords;
private Task _task;

internal QueryEagerEnumerator(IQueryContainer queryContainer, Type type)
{
_queryContainer = queryContainer;
_type = type;
_elements = new ArrayList();
_counter = 0;
Load();
}

public bool MoveNext()
{
_task.Wait();

try
{
_counter++;

if (_elements.Count >= _counter)
{
Current = _elements[_counter];
return true;
}

if (_enumerateDataRecords.Count < _counter)
return false;

var dataRecord = _enumerateDataRecords.ElementAt(_counter - 1);
Current = _queryContainer.AccessLayer.SetPropertysViaReflection(_type.GetClassInfo(), dataRecord);
_elements.Add(Current);

return true;
}
catch (Exception)
{
return false;
}
}

public void Reset()
{
_counter = 0;
}

public object Current { get; private set; }

/// <summary>
/// Mehtod for async loading this will bring us some m secs
/// </summary>
private void Load()
{
_task = new Task(() =>
{
var query = _queryContainer.Compile();
_enumerateDataRecords = _queryContainer.AccessLayer.EnumerateDataRecords(query, true);
});
_task.Start();
}

public void Dispose()
{
if (_task != null)
_task.Dispose();
if (_enumerateDataRecords != null)
_enumerateDataRecords.Clear();
_elements.Clear();
}
}

internal class QueryEagerEnumerator<T> : QueryEagerEnumerator, IEnumerator<T>
{
internal QueryEagerEnumerator(IQueryContainer queryContainer, Type type)
: base(queryContainer, type)
{
}

public new T Current
{
get { return (T)base.Current; }
}
}
}
@@ -1,78 +1,78 @@
/*
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
Please consider to give some Feedback on CodeProject
http://www.codeproject.com/Articles/818690/Yet-Another-ORM-ADO-NET-Wrapper
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using JPB.DataAccess.DbInfoConfig;
using JPB.DataAccess.DbInfoConfig.DbInfo;
using JPB.DataAccess.Manager;
using JPB.DataAccess.Query.Contracts;

namespace JPB.DataAccess.Query
{
/// <summary>
/// </summary>
internal class QueryLazyEnumerator : IEnumerator, IDisposable
{
private readonly DbAccessLayer _accessLayer;
private readonly IDataReader _executeReader;
private readonly DbClassInfoCache _type;

internal QueryLazyEnumerator(IQueryContainer queryContainer, Type type)
{
_type = type.GetClassInfo();
_accessLayer = new DbAccessLayer(queryContainer.AccessLayer.Database);
_accessLayer.Database.Connect(IsolationLevel.ReadCommitted);
_executeReader = queryContainer.Compile().ExecuteReader();
}

public void Dispose()
{
_accessLayer.Database.CloseConnection();
}

public bool MoveNext()
{
if (_executeReader.IsClosed)
{
Dispose();
return false;
}

if (_executeReader.Read())
return true;
return false;
}

public void Reset()
{
throw new NotImplementedException();
}

public object Current
{
get { return _accessLayer.SetPropertysViaReflection(_type, _executeReader); }
}
}

internal class QueryLazyEnumerator<T> : QueryLazyEnumerator, IEnumerator<T>
{
internal QueryLazyEnumerator(IQueryContainer queryContainer, Type type)
: base(queryContainer, type)
{
}

public new T Current
{
get { return (T) base.Current; }
}
}
/*
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
Please consider to give some Feedback on CodeProject
http://www.codeproject.com/Articles/818690/Yet-Another-ORM-ADO-NET-Wrapper
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using JPB.DataAccess.DbInfoConfig;
using JPB.DataAccess.DbInfoConfig.DbInfo;
using JPB.DataAccess.Manager;
using JPB.DataAccess.Query.Contracts;

namespace JPB.DataAccess.Query
{
/// <summary>
/// </summary>
internal class QueryLazyEnumerator : IEnumerator, IDisposable
{
private readonly DbAccessLayer _accessLayer;
private readonly IDataReader _executeReader;
private readonly DbClassInfoCache _type;

internal QueryLazyEnumerator(IQueryContainer queryContainer, Type type)
{
_type = type.GetClassInfo();
_accessLayer = new DbAccessLayer(queryContainer.AccessLayer.Database);
_accessLayer.Database.Connect(IsolationLevel.ReadCommitted);
_executeReader = queryContainer.Compile().ExecuteReader();
}

public void Dispose()
{
_accessLayer.Database.CloseConnection();
}

public bool MoveNext()
{
if (_executeReader.IsClosed)
{
Dispose();
return false;
}

if (_executeReader.Read())
return true;
return false;
}

public void Reset()
{
throw new NotImplementedException();
}

public object Current
{
get { return _accessLayer.SetPropertysViaReflection(_type, _executeReader); }
}
}

internal class QueryLazyEnumerator<T> : QueryLazyEnumerator, IEnumerator<T>
{
internal QueryLazyEnumerator(IQueryContainer queryContainer, Type type)
: base(queryContainer, type)
{
}

public new T Current
{
get { return (T) base.Current; }
}
}
}