What's the better way to implement a condition at NHibernate query?Hidden Features of C#?Best practices for querying with NHibernateHow can you use optional parameters in C#?Best way to repeat a character in C#Proper use of the IDisposable interfaceHow to build a query string for a URL in C#?Implementing INotifyPropertyChanged - does a better way exist?If my interface must return Task what is the best way to have a no-operation implementation?Calculate the execution time of a methodWhy not inherit from List<T>?

What should I do if actually I found a serious flaw in someone's PhD thesis and an article derived from that PhD thesis?

Icon is not displayed in lwc

How should you gracefully leave a company you helped start?

Number of matrices with bounded products of rows and columns

Do predators tend to have vertical slit pupils versus horizontal for prey animals?

Reducing contention in thread-safe LruCache

What are the advantages of this gold finger shape?

Output with the same length always

Alignement of different align environment

Build a mob of suspiciously happy lenny faces ( ͡° ͜ʖ ͡°)

μονάδαι as plural form of μονάς

How does the illumination of the sky from the sun compare to that of the moon?

What would cause a nuclear power plant to break down after 2000 years, but not sooner?

Meaning and structure of headline "Hair it is: A List of ..."

Unconventional examples of mathematical modelling

What was the intention with the Commodore 128?

programming a recursive formula into Mathematica and find the nth position in the sequence

My new Acer Aspire 7 doesn't have a Legacy Boot option, what can I do to get it?

Designing a prison for a telekinetic race

How to prevent criminal gangs from making/buying guns?

If it isn't [someone's name]!

Subgroup generated by a subgroup and a conjugate of it

What happened after the end of the Truman Show?

What does a comma signify in inorganic chemistry?



What's the better way to implement a condition at NHibernate query?


Hidden Features of C#?Best practices for querying with NHibernateHow can you use optional parameters in C#?Best way to repeat a character in C#Proper use of the IDisposable interfaceHow to build a query string for a URL in C#?Implementing INotifyPropertyChanged - does a better way exist?If my interface must return Task what is the best way to have a no-operation implementation?Calculate the execution time of a methodWhy not inherit from List<T>?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am using a generics implementation of Query from NHibernate.

My method:




public IEnumerable<TEntidade> ObterEntidadesPor(Func<TEntidade, bool> where)

return SessionNH.Query<TEntidade>().Where(where);




In this case, the NHibernate first do the "select * from TEntidade" bring all information to memory after all this, he implement the "where" conditional. This are taking to much time.


Is there a better way to do it?










share|improve this question



















  • 1





    why not use Entity Framework, (not sure about NHibernate) but EF translates where to WHERE clause in SQL and doesn't pull all records in memory to do filtering.

    – Aarif
    Mar 27 at 13:26






  • 1





    All applications here are using NHibernate. I can't change to EF without a big impact.

    – Aness Ollem Azuos
    Mar 27 at 13:34







  • 2





    Try with Expression<Func<TEntidade, bool>> where instead

    – Roman Artiukhin
    Mar 27 at 16:06






  • 1





    That's it! The Expression<Func<TEntidade, bool>> where work it. Thanks!

    – Aness Ollem Azuos
    Mar 27 at 18:01

















1















I am using a generics implementation of Query from NHibernate.

My method:




public IEnumerable<TEntidade> ObterEntidadesPor(Func<TEntidade, bool> where)

return SessionNH.Query<TEntidade>().Where(where);




In this case, the NHibernate first do the "select * from TEntidade" bring all information to memory after all this, he implement the "where" conditional. This are taking to much time.


Is there a better way to do it?










share|improve this question



















  • 1





    why not use Entity Framework, (not sure about NHibernate) but EF translates where to WHERE clause in SQL and doesn't pull all records in memory to do filtering.

    – Aarif
    Mar 27 at 13:26






  • 1





    All applications here are using NHibernate. I can't change to EF without a big impact.

    – Aness Ollem Azuos
    Mar 27 at 13:34







  • 2





    Try with Expression<Func<TEntidade, bool>> where instead

    – Roman Artiukhin
    Mar 27 at 16:06






  • 1





    That's it! The Expression<Func<TEntidade, bool>> where work it. Thanks!

    – Aness Ollem Azuos
    Mar 27 at 18:01













1












1








1


2






I am using a generics implementation of Query from NHibernate.

My method:




public IEnumerable<TEntidade> ObterEntidadesPor(Func<TEntidade, bool> where)

return SessionNH.Query<TEntidade>().Where(where);




In this case, the NHibernate first do the "select * from TEntidade" bring all information to memory after all this, he implement the "where" conditional. This are taking to much time.


Is there a better way to do it?










share|improve this question














I am using a generics implementation of Query from NHibernate.

My method:




public IEnumerable<TEntidade> ObterEntidadesPor(Func<TEntidade, bool> where)

return SessionNH.Query<TEntidade>().Where(where);




In this case, the NHibernate first do the "select * from TEntidade" bring all information to memory after all this, he implement the "where" conditional. This are taking to much time.


Is there a better way to do it?







c# nhibernate orm






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 13:22









Aness Ollem AzuosAness Ollem Azuos

381 silver badge9 bronze badges




381 silver badge9 bronze badges










  • 1





    why not use Entity Framework, (not sure about NHibernate) but EF translates where to WHERE clause in SQL and doesn't pull all records in memory to do filtering.

    – Aarif
    Mar 27 at 13:26






  • 1





    All applications here are using NHibernate. I can't change to EF without a big impact.

    – Aness Ollem Azuos
    Mar 27 at 13:34







  • 2





    Try with Expression<Func<TEntidade, bool>> where instead

    – Roman Artiukhin
    Mar 27 at 16:06






  • 1





    That's it! The Expression<Func<TEntidade, bool>> where work it. Thanks!

    – Aness Ollem Azuos
    Mar 27 at 18:01












  • 1





    why not use Entity Framework, (not sure about NHibernate) but EF translates where to WHERE clause in SQL and doesn't pull all records in memory to do filtering.

    – Aarif
    Mar 27 at 13:26






  • 1





    All applications here are using NHibernate. I can't change to EF without a big impact.

    – Aness Ollem Azuos
    Mar 27 at 13:34







  • 2





    Try with Expression<Func<TEntidade, bool>> where instead

    – Roman Artiukhin
    Mar 27 at 16:06






  • 1





    That's it! The Expression<Func<TEntidade, bool>> where work it. Thanks!

    – Aness Ollem Azuos
    Mar 27 at 18:01







1




1





why not use Entity Framework, (not sure about NHibernate) but EF translates where to WHERE clause in SQL and doesn't pull all records in memory to do filtering.

– Aarif
Mar 27 at 13:26





why not use Entity Framework, (not sure about NHibernate) but EF translates where to WHERE clause in SQL and doesn't pull all records in memory to do filtering.

– Aarif
Mar 27 at 13:26




1




1





All applications here are using NHibernate. I can't change to EF without a big impact.

– Aness Ollem Azuos
Mar 27 at 13:34






All applications here are using NHibernate. I can't change to EF without a big impact.

– Aness Ollem Azuos
Mar 27 at 13:34





2




2





Try with Expression<Func<TEntidade, bool>> where instead

– Roman Artiukhin
Mar 27 at 16:06





Try with Expression<Func<TEntidade, bool>> where instead

– Roman Artiukhin
Mar 27 at 16:06




1




1





That's it! The Expression<Func<TEntidade, bool>> where work it. Thanks!

– Aness Ollem Azuos
Mar 27 at 18:01





That's it! The Expression<Func<TEntidade, bool>> where work it. Thanks!

– Aness Ollem Azuos
Mar 27 at 18:01












1 Answer
1






active

oldest

votes


















0














The problem was solved with Expression<func>.



public IEnumerable<TEntidade> ObterEntidadesPor(Expression<Func<TEntidade, bool>> where)

return SessionNH.Query<TEntidade>().Where(where);



While searching for answer, a colleague told me that the Func executes the query before build an expression. To build an expression before executing the query, we have to use Expression.



This is also mentioned by @RomanArtiukhin in comments on question.






share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378281%2fwhats-the-better-way-to-implement-a-condition-at-nhibernate-query%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The problem was solved with Expression<func>.



    public IEnumerable<TEntidade> ObterEntidadesPor(Expression<Func<TEntidade, bool>> where)

    return SessionNH.Query<TEntidade>().Where(where);



    While searching for answer, a colleague told me that the Func executes the query before build an expression. To build an expression before executing the query, we have to use Expression.



    This is also mentioned by @RomanArtiukhin in comments on question.






    share|improve this answer































      0














      The problem was solved with Expression<func>.



      public IEnumerable<TEntidade> ObterEntidadesPor(Expression<Func<TEntidade, bool>> where)

      return SessionNH.Query<TEntidade>().Where(where);



      While searching for answer, a colleague told me that the Func executes the query before build an expression. To build an expression before executing the query, we have to use Expression.



      This is also mentioned by @RomanArtiukhin in comments on question.






      share|improve this answer





























        0












        0








        0







        The problem was solved with Expression<func>.



        public IEnumerable<TEntidade> ObterEntidadesPor(Expression<Func<TEntidade, bool>> where)

        return SessionNH.Query<TEntidade>().Where(where);



        While searching for answer, a colleague told me that the Func executes the query before build an expression. To build an expression before executing the query, we have to use Expression.



        This is also mentioned by @RomanArtiukhin in comments on question.






        share|improve this answer















        The problem was solved with Expression<func>.



        public IEnumerable<TEntidade> ObterEntidadesPor(Expression<Func<TEntidade, bool>> where)

        return SessionNH.Query<TEntidade>().Where(where);



        While searching for answer, a colleague told me that the Func executes the query before build an expression. To build an expression before executing the query, we have to use Expression.



        This is also mentioned by @RomanArtiukhin in comments on question.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 28 at 7:09









        Amit Joshi

        7,7837 gold badges33 silver badges72 bronze badges




        7,7837 gold badges33 silver badges72 bronze badges










        answered Mar 27 at 18:05









        Aness Ollem AzuosAness Ollem Azuos

        381 silver badge9 bronze badges




        381 silver badge9 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378281%2fwhats-the-better-way-to-implement-a-condition-at-nhibernate-query%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript