Print Page | Close Window

Manupulate Object with Query

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2282
Printed Date: 07-Apr-2025 at 4:11am


Topic: Manupulate Object with Query
Posted By: bala
Subject: Manupulate Object with Query
Date 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?



Replies:
Posted By: sbelini
Date 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() )


Posted By: bala
Date 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...



Posted By: sbelini
Date 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.


Posted By: bala
Date 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...



Print Page | Close Window