Willcode4cash icon

Partial dataContext class using Generics

Willcode4cash | PRO | 08/11/16 12:06:21 AM UTC | 0 ⭐ | 297 👁️ | Never ⏰ | []
C# |

1.72 KB

|

None

|

0 👍

/

0 👎

namespace MyApp.Web.Models
{
    using System;
    using System.Collections.Generic;
    using System.Data.Linq;
 
    public partial class MyAppDataContext
    {
        public bool DeleteAllOnSubmit<T>(IEnumerable<T> entities)
        {
            try
            {
                GetTable(typeof(T)).DeleteAllOnSubmit(entities);
                SubmitChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
 
        public bool DeleteOnSubmit<T>(T entity)
        {
            try
            {
                GetTable(typeof(T)).DeleteOnSubmit(entity);
                SubmitChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
 
        public bool InsertAllOnSubmit<T>(IEnumerable<T> entities)
        {
            try
            {
                GetTable(typeof(T)).InsertAllOnSubmit(entities);
                SubmitChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
 
        public bool InsertOnSubmit<T>(ref T entity)
        {
            try
            {
                GetTable(typeof(T)).InsertOnSubmit(entity);
                SubmitChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        partial void OnCreated()
        {
            var options = new DataLoadOptions();
            // Add loadwith elements
            // options.LoadWith<parentClass>(p => p.columnName);
            LoadOptions = options;
        }
    }
}

Comments