Giter Club home page Giter Club logo

Comments (7)

VictorTomaili avatar VictorTomaili commented on July 20, 2024

its c# 6.0 ability.

string.Format("{0}=@fFirstNameParam", "FirstName") 

equal to

$"{nameof(Entity.FirstName)}=@FirstNameParam"

second one has intellisense and refactoring advantage.

if you are new on c# try install visual studio 2015 and use lastes version of c# and .net framework.

from fastcrud.

OleeOlsen avatar OleeOlsen commented on July 20, 2024

Thank you for your fast reply. I'm sorry to say i must use Net 4.5. In your descrition you say it is possible. Please send me an example.

from fastcrud.

VictorTomaili avatar VictorTomaili commented on July 20, 2024

try this. its pure string way.

dbConnection.Find( whereClause:"FirstName=@FirstNameParam", orderClause:"LastName DESC", skipRowsCount:10, limitRowsCount:20, queryParameters: new {FirstNameParam: "John"});

from fastcrud.

OleeOlsen avatar OleeOlsen commented on July 20, 2024

Sorry it dosn't work. The compiler says "not a definition for Find with this parameter".
May be, I'm too stupid ;-)

from fastcrud.

MoonStorm avatar MoonStorm commented on July 20, 2024

@OleeOlsen First of all Ole, welcome to our wonderful C# world. It's beautiful, but it's not gonna be easy for you, as I myself have realized while trying to come up with this simple VB.NET example when I have zero experience in this language.

Imports System.Data.SqlClient
Imports Dapper.FastCrud

Module Module1

    Sub Main()
        Using conn As New SqlConnection
            Dim persons = conn.Find(Of Person)(
                   whereClause := $"{NameOf(Person.FirstName)}=@FirstNameParam",
                   queryParameters := New With{.FirstNameParam="John"})
        End Using
    End Sub

End Module

I hope it makes sense. This translates to C# as follows:

using System.Data.SqlClient;
using Dapper.FastCrud;

namespace YourNamespace
{

    class Program
    {
        static void Main(string[] args)
        {
            using (var conn = new SqlConnection())
            {
                var persons = conn.Find<Person>(
                    whereClause: $"{nameof(Person.FirstName)}=@FirstNameParam",
                    queryParameters: new { FirstNameParam="John" });
            }
        }
    }
}

Both obviously assume there is a class Person defined with FirstName as a string property.

Regardless whether you want to write in VB.NET or C#, you have to use Visual Studio 2015. String interpolation is mostly a language feature, handled by the compiler, thus you can target even .NET 4.5 if you so desire. Just make sure that, before you add the FastCrud Nuget package, your project is already targeting that version of the framework in the Properties => Application screen.

from fastcrud.

OleeOlsen avatar OleeOlsen commented on July 20, 2024

@MoonStorm Thank you for this extendet reply. You shold write a requirement-section in the wiki.
I have now installed VS 2015 and use Net 4.5. And it woks. ;-)

from fastcrud.

MoonStorm avatar MoonStorm commented on July 20, 2024

You're right. I've added more on the front page. Thanks to you, now I know string interpolation was made available in VB 14 😆

from fastcrud.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.