I'm trying to use a generic class to pass in a data object then uses the values within to complete CRUD operations.
class OrderState<TGrainState> : Grain, IState where TGrainState : class
{
protected TGrainState State { get; set; }
public Task Get()
{
using (var context = new SDbContext())
{
var test = typeof(TGrainState).GetProperty("id").GetValue(null);
//int t = (int)test;
//var obj = context.orders.Where(x => x.Id == t);
//return Task.FromResult(obj);
}
return Task.CompletedTask;
}
}
TGrainState is the generic object I want to pass in.
public class State
{
public int Id { get; set; }
public DateTime Created { get; set; }
public string AssignedOrganization { get; set; }
public bool isComplete { get; set; }
public string assignedUser { get; set; }
}
This is the state class I'm attempting to pass into the generic class.
class OrderGrain : OrderState<State>, IOrder
{
public override Task OnActivateAsync()
{
//Should fill the State Object from the Db
Get();
//Sets the information contained in the State to the Object
this.orderInfo = new OrderInfo
{
Id = State.Id,
Created = State.Created,
AssignedOrganization = State.AssignedOrganization,
isComplete = State.isComplete,
assignedUser = State.assignedUser
};
return base.OnActivateAsync();
}
}
Class that inherits from the State Generic class that contains all of the CRUD operations.
So what I'm more or less trying to accomplish is how Microsoft Orleans has it's state setup where you create a state object, operate on that, then call Write(), Update(), Delete(), or Get() to perform the CRUD operation on the DB with Entity Framework using the state data declared.
I might thinking about this wrong or just be completely wrong, so any help would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire