.net inne

Deploy Entity Framework Core

https://www.benday.com/2017/03/17/deploy-entity-framework-core-migrations-from-a-dll/
http://www.learnentityframeworkcore.com/migrations
https://github.com/aspnet/EntityFrameworkCore/issues/6313#issuecomment-287230542

#!/bin/bash

EfMigrationsNamespace=$1
EfMigrationsDllName=$1.dll
EfMigrationsDllDepsJson=$1.deps.json
DllDir=$PWD
EfMigrationsDllDepsJsonPath=$EfMigrationsDllDepsJson
PathToNuGetPackages=$HOME/.nuget/packages
PathToEfDll=$PathToNuGetPackages/microsoft.entityframeworkcore.tools/2.0.1/tools/netcoreapp2.0/ef.dll
 
dotnet exec --depsfile ./$EfMigrationsDllDepsJson --additionalprobingpath $PathToNuGetPackages $PathToEfDll database update \n
--assembly ./$EfMigrationsDllName --startup-assembly ./$EfMigrationsDllName --project-dir . --data-dir $DllDir \n
--verbose --root-namespace $EfMigrationsNamespace
Kategoria: 

git list of merged branches

git branch --merged master
Kategoria: 

JSON Web Tokens

JSON Web Tokens

https://jwt.io/

Kategoria: 

Pomelo sql example

https://docs.microsoft.com/en-us/ef/core/querying/raw-sql
http://www.learnentityframeworkcore.com/raw-sql

using (var context = new SampleContext())
using (var command = context.Database.GetDbConnection().CreateCommand())
{
    command.CommandText = "SELECT * From Table1";
    context.Database.OpenConnection();
    using (var result = command.ExecuteReader())
    {
        // do something with result
    }
}

przykład SQL select

           IQueryable<Setting>  ccc = dbContext.Set<Setting>().FromSql("SELECT * FROM settings");
 
 
           string commandText = "INSERT INTO settings (desc, name, value) VALUES (@desc, @name, @value)";
           var desc = new SqlParameter("@desc", "opis opis");
           var name = new SqlParameter("@name", "test sql insert");
           var value = new SqlParameter("@value", "111");
           dbContext.Database.ExecuteSqlCommand(commandText, desc, name, value);
Kategoria: 

Pomelo update example

var row_updated = db.Articles
.Where(x => x.Id <= 10)
.Where(x => x.Title == "Hello World")
.Where(x => DateTime.Now >= x.Time)
.SetField(x => x.Title).Prepend("[old] ")
.SetField(x => x.IsPinned).WithValue(true)
.Update();

var row_updated2 = db.Articles
.Where(x => db.Users.Where(y => y.Id %2 == 0).Select(y=>y.Id).Contains(x.Id))
.Delete();

Kategoria: 

Many-to-many EF core

Entity core manual
https://docs.microsoft.com/en-us/ef/core/modeling/relationships#many-to-...

-----------
Zero to One

You can do it declaring your foreign key like in the following:

public class Blog
{

public int BlogId { get; set; }
public List Posts { get; set; }

}

public class Post
{
public int PostId { get; set; }
public int? PostId { get; set; }
public virtual Blog Blog { get; set; }
}

M2M

Creating:
1. Create new XY
2. Set XY.X = New X
3. Set XY.Y = New Y
4. Db.SaveChanges()

Deleting:
1. Find and delete XY
2. Db.SaveChanges()

Thanks,

Jeff Bowman

Fairbanks, Alaska

Kategoria: 

Strony

Subskrybuj .net inne