liuhaipeng905 / servicestack

Automatically exported from code.google.com/p/servicestack
0 stars 1 forks source link

GetByID seems doesn't to work against POCO objects #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

here is the code:

 Console.WriteLine("test7 start");
            var rc = new RedisClient();

            var u = ServiceLayerContext.ServiceUsers.GetByID(6);
            Console.WriteLine("Show what we have in DTO");
            Console.WriteLine(u.ToValueObject().Dump());
            Console.WriteLine("Save in Redis");
            rc.Add("test2", u.ToValueObject(), TimeSpan.FromSeconds(20));
            Console.WriteLine("Getting from Redis");
            var t = rc.GetById<Engine.BLL.DTO.User>("test2");
            Console.WriteLine("Dumping to show nothing extracted");
            Console.WriteLine(t.Dump());

that's what I get:

Show what we have in DTO
{
        UserID: 3,
        FirstName: John,
        LastName: Smith,
        Email: john@smith.com,
        Password: test,
        ID: 0,
        Created: 0001-01-01,
        TypeID: User
}
Save in Redis
Getting from Redis
Dumping to show nothing extracted

Question:

what I'm doing wrong?

Redis said one key added: http://screencast.com/t/ZmJlZTAz

if I change the code to use typed provider:

public void test8()
        {
            Console.WriteLine("test7 start");

            var rc = new RedisClient("localhost", 6379).GetTypedClient<Engine.BLL.DTO.User>();

            var u = ServiceLayerContext.ServiceUsers.GetByID(6);
            Console.WriteLine("Show what we have in DTO");
            Console.WriteLine(u.ToValueObject().Dump());
            Console.WriteLine("Save in Redis");
            rc.Store(u.ToValueObject());
            Console.WriteLine("Getting from Redis");
            var t = rc.GetAll();
            Console.WriteLine("Dumping to show nothing extracted");
            Console.WriteLine(t.Dump());

        }

it's getting better: http://screencast.com/t/NmVhNjQ4N

but the problem is that if I change IDs in the call here:             
var u = ServiceLayerContext.ServiceUsers.GetByID(7); and then 
var u = ServiceLayerContext.ServiceUsers.GetByID(8);

those IDs present in DB and returned by this class. I still get only one record 
in DUMP.
http://screencast.com/t/ODMzMGI0YzE

so it rewrites the old one immediately. The only way I can store several 
records if I do this

public void test8()
        {
            Console.WriteLine("test7 start");

            var rc = new RedisClient("localhost", 6379).GetTypedClient<Engine.BLL.DTO.User>();

            var u = ServiceLayerContext.ServiceUsers.GetByID(6);
            rc.Store(u.ToValueObject());
            u = ServiceLayerContext.ServiceUsers.GetByID(7);
            rc.Store(u.ToValueObject());
            u = ServiceLayerContext.ServiceUsers.GetByID(8);
            rc.Store(u.ToValueObject());
            Console.WriteLine("Getting from Redis");
            var t = rc.GetAll();
            Console.WriteLine("Dumping to show nothing extracted");
            Console.WriteLine(t.Dump());

        }

so then in one run I'll get records in redis. Please let me know the solution

Original issue reported on code.google.com by interes...@gmail.com on 7 Jul 2010 at 3:10

GoogleCodeExporter commented 9 years ago
Console.WriteLine("test7 start");

            var rc = new RedisClient("localhost", 6379);
            var u = ServiceLayerContext.ServiceUsers.GetByID(8);
            rc.Add("z", u.ToValueObject(), TimeSpan.FromSeconds(20));
            var t = rc.GetById<Engine.BLL.DTO.User>("z");
            Console.WriteLine(t.Dump());

this is also returns nothing;

Original comment by interes...@gmail.com on 7 Jul 2010 at 3:17

GoogleCodeExporter commented 9 years ago
however this one
Console.WriteLine("test7 start");

            var rc = new RedisClient("localhost", 6379);
            var u = ServiceLayerContext.ServiceUsers.GetByID(8);
            rc.Add("z", u.ToValueObject(), TimeSpan.FromSeconds(20));
            var t = rc.GetAll<Engine.BLL.DTO.User>();
            Console.WriteLine(t.Dump());

where getByID is replaced with GetALL returns the data: 
http://screencast.com/t/MDlmZTQ3Y

any ideas?

Original comment by interes...@gmail.com on 7 Jul 2010 at 3:19

GoogleCodeExporter commented 9 years ago
I'm trying to use the REDIS as cache layer in app.

Original comment by interes...@gmail.com on 7 Jul 2010 at 3:20

GoogleCodeExporter commented 9 years ago
Hey sorry its taken a while to respond, I just saw this issue now, looks like 
we're operating in different time zones :)

Ok I think your problem is that 'GetById' looks for a property named 'Id' not 
'ID'. Try changing the property name to 'Id' and give it another go.

Original comment by demis.be...@gmail.com on 7 Jul 2010 at 7:36

GoogleCodeExporter commented 9 years ago
You're right now it works. But still partially.

var rc = new RedisClient("localhost", 
6379).GetTypedClient<Engine.BLL.DTO.User>();
var u = ServiceLayerContext.ServiceUsers.GetByID(8);
Console.WriteLine("Show what we have in DTO");
Console.WriteLine(u.ToValueObject().Dump());

Console.WriteLine("Save in Redis");
//rc.Store(u.ToValueObject());
rc.SetEntry("x", u.ToValueObject(),TimeSpan.FromSeconds(10));

Console.WriteLine("Getting from Redis");
var t = rc.GetAll();
//var t = rc.GetById("7");
Console.WriteLine("Dumping to show nothing extracted");
Console.WriteLine(t.Dump());

so opearatuin rc.Store(u.ToValueObject()); has worked. But then I tried 
rc.SetEntry("x", u.toValueObject(), TimeSpan.FromSeconds(10)); and nothing has 
been stored.

so how can I store the object that should be expired in 10 secs?

Original comment by dmitrys...@gmail.com on 7 Jul 2010 at 10:08

GoogleCodeExporter commented 9 years ago
also I'm curious why this one doesn't work

Console.WriteLine("test7 start");
            var u = ServiceLayerContext.ServiceUsers.GetByID(6);
            Console.WriteLine("Show what we have in DTO");
            Console.WriteLine(u.ToValueObject().Dump());
            Console.WriteLine("Save in Redis");
            rc.Add("test2", u.ToValueObject(), TimeSpan.FromSeconds(20));
            Console.WriteLine("Getting from Redis");
            var t = rc.GetById<Engine.BLL.DTO.User>("test2");
            Console.WriteLine("Dumping to show nothing extracted");
            Console.WriteLine(t.Dump());

see what I get
http://screencast.com/t/ZjIwOTYzNTQ
rc.GetALL also produces zero result

Original comment by dmitrys...@gmail.com on 7 Jul 2010 at 10:19

GoogleCodeExporter commented 9 years ago
however the add/set operators seems to work:
http://screencast.com/t/YzIzZGYyMzkt
redis shows that I have data posted, but it seems none of GET method works. 
Please clarify how to use the calls properly or if they aren't working (bug). 

Original comment by dmitrys...@gmail.com on 7 Jul 2010 at 10:22

GoogleCodeExporter commented 9 years ago
Hi Dimitry,

Is it possible that 'Engine.BLL.DTO.User' is not the same type as 
'u.ToValueObject()'?
Otherwise can you please submit a stand alone unit test or program so I can 
tell you exactly why it doesn't work or what the expected behaviour should be?

- Demis

Original comment by demis.be...@gmail.com on 7 Jul 2010 at 11:06

GoogleCodeExporter commented 9 years ago
it seems it's working now. Thanks Demis for quick response.

Original comment by dmitrys...@gmail.com on 8 Jul 2010 at 3:12

GoogleCodeExporter commented 9 years ago
Cool, good to know!

Original comment by demis.be...@gmail.com on 8 Jul 2010 at 7:46