Example #1
0
        public string PkWhereSqlForPartialKeys(int numberOfKeys)
        {
            if (numberOfKeys == PKs.Count)
            {
                return(PkWhereSql);
            }

            return(PKs.Take(numberOfKeys).Aggregate(new StringBuilder(), (sb, pk) => sb.AppendFormat(" \"{0}\" = ? and", pk.Name), sb => sb.Remove(sb.Length - 3, 3).ToString()));
        }
Example #2
0
        public TableMapping(Type type, IEnumerable <PropertyInfo> properties, CreateFlags createFlags = CreateFlags.None, IColumnInformationProvider infoProvider = null)
        {
            if (infoProvider == null)
            {
                infoProvider = new DefaultColumnInformationProvider();
            }

            MappedType = type;

            var tableAttr = type.GetTypeInfo().GetCustomAttributes <TableAttribute>().FirstOrDefault();

            TableName = tableAttr != null ? tableAttr.Name : MappedType.Name;

            var props = properties;

            var cols = new List <Column>();

            foreach (var p in props)
            {
                var ignore = infoProvider.IsIgnored(p);

                if (p.CanWrite && !ignore)
                {
                    cols.Add(new Column(p, createFlags));
                }
            }
            Columns = cols.ToArray();
            foreach (var c in Columns)
            {
                if (c.IsAutoInc && c.IsPK)
                {
                    _autoPk = c;
                }
                if (c.IsPK)
                {
                    PKs.Add(c);
                }
            }

            HasAutoIncPK = _autoPk != null;

            if (PK != null)
            {
                GetByPrimaryKeySql  = string.Format("select * from \"{0}\" where \"{1}\" = ?", TableName, PK.Name);
                PkWhereSql          = PKs.Aggregate(new StringBuilder(), (sb, pk) => sb.AppendFormat(" \"{0}\" = ? and", pk.Name), sb => sb.Remove(sb.Length - 3, 3).ToString());
                GetByPrimaryKeysSql = String.Format("select * from \"{0}\" where {1}", TableName, PkWhereSql);
            }
            else
            {
                // People should not be calling Get/Find without a PK
                GetByPrimaryKeysSql = GetByPrimaryKeySql = string.Format("select * from \"{0}\" limit 1", TableName);
            }
        }
Example #3
0
 /// <summary>
 /// tables without a primary key cannot participate in the interface - the primary key is used for navigation (see the Navigator class)
 /// </summary>
 /// <returns>list of the tables</returns>
 public List <string> TablesMissingPK()
 {
     return((from tbl in Tables where !PKs.ContainsKey(tbl) select tbl).ToList <string>());
 }