Last active
May 2, 2018 07:19
-
-
Save abdulmajedsulim/04afdd783c2d0f999d670876521bdeba to your computer and use it in GitHub Desktop.
Issue in OrmLite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ServiceStack.DataAnnotations; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace StoreSystem.Core | |
{ | |
public class BaseEntity | |
{ | |
[PrimaryKey] | |
[AutoIncrement] | |
public int Id { get; set; } | |
[CustomField("nvarchar(4000)")] | |
public string Name { get; set; } | |
[CustomField("nvarchar(4000)")] | |
public string Description { get; set; } | |
public bool IsDeleted { get; set; } | |
public byte[] Version { get; set; } | |
public int? CreatedByID { get; set; } | |
public DateTime? CreatedAt { get; set; } | |
public int? UpdatedByID { get; set; } | |
public DateTime? UpdatedAt { get; set; } | |
} | |
public class Store : BaseEntity | |
{ | |
[CustomField("NVARCHAR(4000)")] | |
public string StoreNumber { get; set; } | |
[Reference] | |
public List<Authorizers> Authorizers { get; set; } | |
[CustomField("NVARCHAR(4000)")] | |
public string ClientName { get; set; } | |
[CustomField("NVARCHAR(20)")] | |
public string ClientMobile { get; set; } | |
[CustomField("NVARCHAR(4000)")] | |
public string ClientEmail { get; set; } | |
public void Update() | |
{ | |
UnitOfWork.Obj.DB.Save(this, true); | |
} | |
} | |
public class Authorizers : BaseEntity | |
{ | |
[ForeignKey(typeof(Store),OnDelete = "CASCADE")] | |
public int StoreID { get; set; } | |
public int CaseAuthorizerId { get; set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Net; | |
using System.Threading.Tasks; | |
using System.Web; | |
using System.Web.Mvc; | |
namespace Store.WebApp.Controllers | |
{ | |
[Authorize()] | |
public class StoreController : Controller | |
{ | |
public ActionResult SaveStore(StoreModel model) | |
{ | |
var authorizersList = new List<Authorizers>(); | |
foreach (var item in model.Authorizers) | |
{ | |
authorizersList.Add(new Authorizers() { CaseAuthorizerId = item }); | |
} | |
Store mystore = new Stroe(); | |
mystore.Authorizers=authorizersList; | |
myStore.Update(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.Data.Entity.Infrastructure; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using ServiceStack.OrmLite; | |
namespace Store.Services | |
{ | |
public class UnitOfWork | |
{ | |
public IDbConnection DB { get; set; } | |
private OrmLiteConnectionFactory DbFactory; | |
public static UnitOfWork Obj { get; private set; } | |
private static string CnnStr = System.Configuration.ConfigurationManager.ConnectionStrings["CnnStr"].ConnectionString; | |
static UnitOfWork() | |
{ | |
Obj = new UnitOfWork(CnnStr); | |
} | |
public UnitOfWork(string connectionString) | |
{ | |
if(DbFactory == null) | |
{ | |
DbFactory = new OrmLiteConnectionFactory(CnnStr, SqlServer2016Dialect.Provider); | |
OrmLiteConfig.DialectProvider.GetStringConverter().UseUnicode = true; | |
} | |
DB = DbFactory.OpenDbConnection(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment