<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Forum Pasja Informatyki - Najnowsze z tagiem entityframework</title>
<link>https://forum.pasja-informatyki.pl/tag/entityframework</link>
<description>Powered by Question2Answer</description>
<item>
<title>C# - Encja z lista a seed danych do bazy</title>
<link>https://forum.pasja-informatyki.pl/571460/c%23-encja-z-lista-a-seed-danych-do-bazy</link>
<description>

&lt;p&gt;Cześć, mam problem z seed'owaniem danych do bazy danych MySql. Uzywam Entityframeworkcore oraz PomeloMySql. Poniewaz lista musi posiadac primary key, nie moge uzyc zwyklej listy stringow, tylko musialem stworzyc klase ktora jest generykiem mojej listy. To z kolei rodzi ponizszy problem.&lt;/p&gt;



&lt;p&gt;Moja encja wyglada tak:&lt;/p&gt;



&lt;pre class=&quot;brush:csharp;&quot;&gt;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace FoodIdea.API.Entities
{
    public class Recipe
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
        public List&amp;lt;IngredientsClass&amp;gt; Ingredients { get; set; } = new List&amp;lt;IngredientsClass&amp;gt;();
        public int PreparationTime { get; set; }
        public bool IsHardToDo { get; set; }
        public double TasteRate { get; set; }

        public class IngredientsClass
        {
            [Key]
            public int Id { get; set; }
            public string Ingredient { get; set; } = null!;

        }

        [ForeignKey(&quot;FoodId&quot;)]
        public Food? Food { get; set; }

        public int FoodId { get; set; }
    }
}
&lt;/pre&gt;



&lt;p&gt;a seed tak:&lt;/p&gt;



&lt;pre class=&quot;brush:csharp;highlight:[8,9,10,11,12];&quot; title=&quot;IEnumerable&quot;&gt;
modelBuilder.Entity&amp;lt;Recipe&amp;gt;()
                .HasData(
                new Recipe()
                {
                    Id = 1,
                    FoodId = 1,
                    PreparationTime = 30,
                    Ingredients = {
                    new IngredientsClass() { Ingredient = &quot;tomato&quot;, Id = 1 },
                    new IngredientsClass() { Ingredient = &quot;salad&quot;, Id = 2 },
                    new IngredientsClass() { Ingredient = &quot;pasta&quot;, Id = 3 },
                    new IngredientsClass() { Ingredient = &quot;pizza&quot;, Id = 4 }},
                    IsHardToDo = false,
                    TasteRate = 8
                }&lt;/pre&gt;



&lt;p&gt;Otrzymuje bład:&lt;/p&gt;



&lt;pre class=&quot;brush:csharp;&quot;&gt;
The seed entity for entity type 'Recipe' cannot be added because it has the navigation 'Ingredients' set.&lt;/pre&gt;



&lt;p&gt;Za jakiekolwiek sugestie będę wdzięczny&amp;nbsp;&lt;/p&gt;</description>
<category>C#</category>
<guid isPermaLink="true">https://forum.pasja-informatyki.pl/571460/c%23-encja-z-lista-a-seed-danych-do-bazy</guid>
<pubDate>Fri, 02 Sep 2022 17:27:59 +0000</pubDate>
</item>
<item>
<title>System logowania C#</title>
<link>https://forum.pasja-informatyki.pl/477882/system-logowania-c%23</link>
<description>

&lt;p&gt;Witam,&lt;/p&gt;



&lt;p&gt;Aplikacja WinForms.&lt;/p&gt;



&lt;p&gt;Mam stworzony model bazy danych z wykorzystaniem Entity Framework.&lt;/p&gt;



&lt;p&gt;Baza danych to Sql Server.&lt;/p&gt;



&lt;p&gt;Wysyłam do bazy takie zapytanie w Linqu które sprawdza poprawność loginu i hasła.&lt;/p&gt;



&lt;pre class=&quot;brush:plain;&quot;&gt;
var idEmployee = shopContext.Users
                .Where(x =&amp;gt; (x.Login == login) &amp;amp;&amp;amp; (x.Password == password))
                .Select(x =&amp;gt; x.Idemployee).FirstOrDefault().ToString();&lt;/pre&gt;



&lt;p&gt;Wszystko działa spoko oprócz tego że kiedy zapytanie wysyła do bazy login/hasło np. zamiast Haslo123 to HASLo123 to i tak baza danych mówi mu że oba stringi są takie same no a nie są bo jest różna wielkość znaków.&lt;/p&gt;



&lt;p&gt;Co można zrobić w tej sytuacji?&lt;/p&gt;</description>
<category>C#</category>
<guid isPermaLink="true">https://forum.pasja-informatyki.pl/477882/system-logowania-c%23</guid>
<pubDate>Tue, 24 Mar 2020 12:48:50 +0000</pubDate>
</item>
<item>
<title>Nieznany błąd w connection string dla update-database</title>
<link>https://forum.pasja-informatyki.pl/428095/nieznany-blad-w-connection-string-dla-update-database</link>
<description>

&lt;p&gt;Witam serdecznie. Ostatnio zacząłem pisać bibliotekę do aplikacji, która byłaby odpowiedzialna za łączenie się z bazą danych MySql. Postanowiłem skorzystać z EntityFramework. Konsola NuGet'a wypisuje mi błąd, gdy podaje polecenie update-database. Oto kod błędu:&lt;/p&gt;



&lt;pre class=&quot;brush:plain;&quot;&gt;
System.FormatException: Nieprawidłowy format ciągu wejściowego.
   w System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
   w System.Convert.ToDouble(String value)
   w MySql.Data.EntityFramework.MySqlMigrationSqlGenerator.Generate(CreateIndexOperation op)
   w MySql.Data.EntityFramework.MySqlMigrationSqlGenerator.&amp;lt;.ctor&amp;gt;b__22_4(MigrationOperation op)
   w MySql.Data.EntityFramework.MySqlMigrationSqlGenerator.Generate(IEnumerable`1 migrationOperations, String providerManifestToken)
   w System.Data.Entity.Migrations.DbMigrator.GenerateStatements(IList`1 operations, String migrationId)
   w System.Data.Entity.Migrations.Infrastructure.MigratorBase.GenerateStatements(IList`1 operations, String migrationId)
   w System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, VersionedModel targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto)
   w System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   w System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   w System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   w System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   w System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
   w System.Data.Entity.Migrations.DbMigrator.&amp;lt;&amp;gt;c__DisplayClasse.&amp;lt;Update&amp;gt;b__d()
   w System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   w System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   w System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
   w System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
   w System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
   w System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Nieprawidłowy format ciągu wejściowego.&lt;/pre&gt;



&lt;p&gt;Kod App.config:&lt;/p&gt;



&lt;pre class=&quot;brush:xml;&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;configuration&amp;gt;
  &amp;lt;configSections&amp;gt;
		&amp;lt;section name=&quot;entityFramework&quot; type=&quot;System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral&quot; requirePermission=&quot;false&quot; /&amp;gt;
	&amp;lt;/configSections&amp;gt;
		&amp;lt;entityFramework&amp;gt;
			&amp;lt;defaultConnectionFactory type=&quot;System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework&quot;&amp;gt;
				&amp;lt;parameters&amp;gt;
					&amp;lt;parameter value=&quot;v12.0&quot; /&amp;gt;
				&amp;lt;/parameters&amp;gt;
			&amp;lt;/defaultConnectionFactory&amp;gt;
		&amp;lt;providers&amp;gt;
			&amp;lt;provider invariantName=&quot;System.Data.SqlClient&quot; type=&quot;System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer&quot; /&amp;gt;
			&amp;lt;provider invariantName=&quot;MySql.Data.MySqlClient&quot; type=&quot;MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.16.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d&quot;/&amp;gt;
    &amp;lt;/providers&amp;gt;
	&amp;lt;/entityFramework&amp;gt;
  &amp;lt;runtime&amp;gt;
    &amp;lt;assemblyBinding xmlns=&quot;urn:schemas-microsoft-com:asm.v1&quot;&amp;gt;
      &amp;lt;dependentAssembly&amp;gt;
        &amp;lt;assemblyIdentity name=&quot;MySql.Data&quot; publicKeyToken=&quot;c5687fc88969c44d&quot; culture=&quot;neutral&quot; /&amp;gt;
        &amp;lt;bindingRedirect oldVersion=&quot;0.0.0.0-8.0.16.0&quot; newVersion=&quot;8.0.16.0&quot; /&amp;gt;
      &amp;lt;/dependentAssembly&amp;gt;
    &amp;lt;/assemblyBinding&amp;gt;
  &amp;lt;/runtime&amp;gt;
	&amp;lt;connectionStrings&amp;gt;
		&amp;lt;add name=&quot;educationdb&quot; providerName=&quot;MySql.Data.MySqlClient&quot; connectionString=&quot;server=localhost;uid=user;pwd=jAwQsqrulqoc7NFr;database=educationdb&quot; /&amp;gt;
	&amp;lt;/connectionStrings&amp;gt;
&amp;lt;/configuration&amp;gt;&lt;/pre&gt;



&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
<category>C#</category>
<guid isPermaLink="true">https://forum.pasja-informatyki.pl/428095/nieznany-blad-w-connection-string-dla-update-database</guid>
<pubDate>Mon, 29 Apr 2019 08:59:35 +0000</pubDate>
</item>
<item>
<title>WYkorzystanie klasy ViewModel do prezentacji widoku.</title>
<link>https://forum.pasja-informatyki.pl/392732/wykorzystanie-klasy-viewmodel-do-prezentacji-widoku</link>
<description>

&lt;p&gt;Witam,&lt;/p&gt;



&lt;p&gt;Mój kod:&lt;/p&gt;



&lt;pre class=&quot;brush:csharp;&quot;&gt;
public class Student
{
    public int StudentId { get; set; }
    public string StudentName { get; set; }
    public int IndexNumber { get; set; }

    public ICollection&amp;lt;Course&amp;gt; Course { get; set; }
}
public class Course
{
    public int CourseId { get; set; }
    public string CoureName { get; set; }
    public int NumberHours { get; set; }
    public bool IsExam { get; set; }

    public ICollection&amp;lt;Student&amp;gt; Student { get; set; }

}
public class ScheduleVM
{
    public string StudentName { get; set; } // Student class
    public int IndexNumber { get; set; }    // Student class
    public string CourseName { get; set; }   // Course class

}

public class ModelContext : DbContext
{
    public ModelContext()
        : base(&quot;name=ModelContext&quot;)
    {}

    public DbSet&amp;lt;Student&amp;gt; Students { get; set; }
    public DbSet&amp;lt;Course&amp;gt; Courses { get; set; }

}&lt;/pre&gt;



&lt;p&gt;Mam dwie klasy modelu oraz klasę ViewModel, w której chcę pokazać wybrane dane. Klasa ScheduleVM nie istnieje w klasie kontekstu, nie mam pomysłu jak pobrać dane z bazy i wyświetlić tylko te wybrane. Do tabel Student i Course dane mam dodane.&lt;/p&gt;



&lt;p&gt;Mam taki pomysł, aby w kontrolerze Schedule stworzyć List&amp;lt;ScheduleVM&amp;gt; i w osobnych metodach pobierać wybrane dane i zapisywać je do listy ? czy takie rozwiązanie ma sens ?&lt;/p&gt;



&lt;p&gt;&amp;nbsp;&lt;/p&gt;



&lt;p&gt;Pozdrawiam.&lt;/p&gt;</description>
<category>C#</category>
<guid isPermaLink="true">https://forum.pasja-informatyki.pl/392732/wykorzystanie-klasy-viewmodel-do-prezentacji-widoku</guid>
<pubDate>Sun, 11 Nov 2018 19:12:53 +0000</pubDate>
</item>
<item>
<title>ASP.NET, MVC Upload plików</title>
<link>https://forum.pasja-informatyki.pl/289842/asp-net-mvc-upload-plikow</link>
<description>

&lt;p&gt;Cześć!
&lt;br&gt;
Generalnie chce zakupić serwer. Różnego typu firmy hostingowe oferują przestrzeń dyskową www i przestrzeń dyskową bazy danych. I teraz pytanie, czy jeśli wgrywam plik typu .jpg, .doc, czy prezentacja to plik zostaje umieszczony w bazie danych, czy tylko informacje o nim, a sam plik w sobie na przestrzeni dyskowej strony www?
&lt;br&gt;
Niżej zamieszczam moje metody :)&lt;/p&gt;



&lt;pre class=&quot;brush:csharp;&quot;&gt;
public ActionResult FileUpload()
        {
            var model = new FileUploadViewModel();
            return View(model);
        }

        [HttpPost]
        public ActionResult FileUpload(FileUploadViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            FileUploadDBModel fileUploadModel = new FileUploadDBModel();

            byte[] uploadFile = new byte[model.File.InputStream.Length];
            model.File.InputStream.Read(uploadFile, 0, uploadFile.Length);

            fileUploadModel.FileName = model.File.FileName;
            fileUploadModel.File = uploadFile;

            var userId = User.Identity.GetUserId();
            fileUploadModel.UserID = userId;
            fileUploadModel.ID = Guid.NewGuid();

            context.FileUploadDBModels.Add(fileUploadModel);
            context.SaveChanges();

            return RedirectToAction(&quot;Index&quot;, &quot;UsersFile&quot;);
        }&lt;/pre&gt;



&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
<category>C#</category>
<guid isPermaLink="true">https://forum.pasja-informatyki.pl/289842/asp-net-mvc-upload-plikow</guid>
<pubDate>Sat, 30 Sep 2017 18:16:31 +0000</pubDate>
</item>
<item>
<title>Rozbudowana baza danych w modelu ASP.NET MVC</title>
<link>https://forum.pasja-informatyki.pl/285967/rozbudowana-baza-danych-w-modelu-asp-net-mvc</link>
<description>Witam serdecznie.&lt;br /&gt;
&lt;br /&gt;
Realizuję projekt, w której będą firmy (które mogą generować sobie różne dokumenty na stronce), każda firma ma swoje dane ale i swoich użytkowników. Programista dodaje Firmę i Admina, admin tworzy innych swoich użytkowników. I teraz czy lepiej będzie w we wszystkich tabelach tworzyć kolumnę &amp;quot;IdFirmy&amp;quot; żeby było wiadomo czyje są dane czy firmy X i Y? Czy lepiej osobne bazy danych dla osobnych firm? Jak będzie to lepiej działać? Tabel jest przynajmniej z 10. Na miesiąc w każdej tabeli powstaje około 40-50 rekordów. &lt;br /&gt;
&lt;br /&gt;
Jaka architektura będzie najlepsza? Proszę o chociaż naprowadzenie na temat jakiś artykuł ang czy coś w tym rodzaju.&lt;br /&gt;
&lt;br /&gt;
Z góry dzięki.</description>
<category>C#</category>
<guid isPermaLink="true">https://forum.pasja-informatyki.pl/285967/rozbudowana-baza-danych-w-modelu-asp-net-mvc</guid>
<pubDate>Sat, 16 Sep 2017 11:45:25 +0000</pubDate>
</item>
</channel>
</rss>