New Posts New Posts RSS Feed: Manupulate Object with Query
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Manupulate Object with Query

 Post Reply Post Reply
Author
bala View Drop Down
Groupie
Groupie
Avatar

Joined: 18-Aug-2010
Location: Brazil
Posts: 54
Post Options Post Options   Quote bala Quote  Post ReplyReply Direct Link To This Post Topic: Manupulate Object with Query
    Posted: 03-Nov-2010 at 9:50am
hi
I am creating an object and inserting some values in object.Then i manupulating with
this object with navigation.
Its not able to manupulate object with navigation property..

How can add or manupulated object with navigation before saving in database...

Any Help?
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 03-Nov-2010 at 10:29am
Hi,
 
Not sure I understand what you are trying to do... Can you clarify?
By the way, are you adding your entity (object) to the Entity Manager? (i.e. em.AddEntity(entity) or entity.AddToManager() )
Back to Top
bala View Drop Down
Groupie
Groupie
Avatar

Joined: 18-Aug-2010
Location: Brazil
Posts: 54
Post Options Post Options   Quote bala Quote  Post ReplyReply Direct Link To This Post Posted: 03-Nov-2010 at 11:06am
Hi
i´m sending code plus my Enitiy model diagram.

//Here i have object name PessoaObservacao and try to adding data

PESSOA_TIPO_USUARIO usuario = (EntitiesCrmall.DefaultManager.Principal as PESSOA_TIPO_USUARIO);

     PessoaObservacao  = new PESSOA_OBSERVACAO;      
                PessoaObservacao.FK_USUARIO = usuario.FK_PESSOA;
                PessoaObservacao.OBSERVACAO = textEdit1.Text;
                PessoaObservacao.PRIVADO = chkPrivado.IsChecked == true ? "S" : "N";

           Pessoa.PESSOA_OBSERVACAO.Add(PessoaObservacao);

               DialogResult = true;     

Now I am setting PessoaObervacao object in Observablecollection of type    PESSOA_OBSERVACAO.

Then I display that data on grid.But i want to show  Name from  PESSOA_FISICA.

I am attaching my Entity model image...

Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 10-Nov-2010 at 3:28pm
You mention that you "want to show Name from  PESSOA_FISICA". Do you want to do that based on a given PESSOA_OBSERVACAO?
If that's the case, you could do:
 
var aPessoaFisicaName = pessoaObservacao.PESSOA.PESSOA_FISICA
  .Where(pf => pf.CPF == "999999999")
  .Select(pf => pf.Name);
 
 
or if you want to navigate from PESSOA_OBSERVACAO to PESSOA and finally to PESSOA_FISICA you could do
 
name = mgr.PESSOA_OBSERVACAO
  //.With(QueryStrategy.CacheOnly)
  .Select(po => po.PESSOA)
  .SelectMany(p => p.PESSOA_FISICA)
  .Where(pf => pf.CPF == "999999999")
  .Select(pf => pf.Name)
  .First();
 Something to be aware about the query above is that if you do the query normally the QueryStrategy is "Normal" which uses an "optimized' fetch Strategy.  This is normally DataSourceThenCache, but it the query cannot be inverted then it turns into a DataSourceOnly query. Therefore you would get no results (if the data is not saved to the datasource yet).
You will need to change your query strategy to DataSourceThenCache explicitly (AND turn off query inversion) then you will be able to get the results that you expect. You could also use CacheOnly strategy, but I don't think it'd be the best approach.
 
Please let me know if this is the answer that you are looking for.
 
Regards,
   Silvio.
Back to Top
bala View Drop Down
Groupie
Groupie
Avatar

Joined: 18-Aug-2010
Location: Brazil
Posts: 54
Post Options Post Options   Quote bala Quote  Post ReplyReply Direct Link To This Post Posted: 12-Nov-2010 at 11:22am
Hi Silvio
Due to some other work I could not figure out this problem.
I will work on it and tell you result..

Thanks...
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down