Skip to content

Instantly share code, notes, and snippets.

@jogibear9988
Created March 15, 2013 13:36
Show Gist options
  • Save jogibear9988/5169904 to your computer and use it in GitHub Desktop.
Save jogibear9988/5169904 to your computer and use it in GitHub Desktop.
ManyToManyAssosiation.cs
using System;
using JNotNull = JetBrains.Annotations.NotNullAttribute;
namespace BLToolkit.Mapping
{
using Common;
using Reflection;
public class ManyToManyAssociation
{
public ManyToManyAssociation(
[JNotNull] MemberAccessor memberAccessor,
[JNotNull] string[] thisKey,
[JNotNull] string[] otherKey,
string storage,
bool canBeNull,
string[] relThisKey,
string[] relOtherKey,
string relTableName)
{
if (memberAccessor == null) throw new ArgumentNullException("memberAccessor");
if (thisKey == null) throw new ArgumentNullException("thisKey");
if (otherKey == null) throw new ArgumentNullException("otherKey");
if (thisKey.Length == 0)
throw new ArgumentOutOfRangeException(
"thisKey",
string.Format("Association '{0}.{1}' does not define keys.", memberAccessor.TypeAccessor.Type.Name, memberAccessor.Name));
if (thisKey.Length != otherKey.Length)
throw new ArgumentException(
string.Format(
"Association '{0}.{1}' has different number of keys for parent and child objects.",
memberAccessor.TypeAccessor.Type.Name, memberAccessor.Name));
MemberAccessor = memberAccessor;
ThisKey = thisKey;
OtherKey = otherKey;
Storage = storage;
CanBeNull = canBeNull;
RelThisKey = relThisKey;
RelOtherKey = relOtherKey;
RelTableName = relTableName;
}
public MemberAccessor MemberAccessor { get; set; }
public string[] ThisKey { get; set; }
public string[] OtherKey { get; set; }
public string Storage { get; set; }
public bool CanBeNull { get; set; }
public string[] RelThisKey { get; set; }
public string[] RelOtherKey { get; set; }
public string RelTableName { get; set; }
public static string[] ParseKeys(string keys)
{
return keys == null ? Array<string>.Empty : keys.Replace(" ", "").Split(',');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment