<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Entity Framework &#8211; Stefan Meyer</title>
	<atom:link href="https://blog.meyer-luenen.de/category/programmieren/net/entity-framework/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.meyer-luenen.de</link>
	<description>Lose-Blatt-Sammlung</description>
	<lastBuildDate>Sun, 17 Dec 2023 12:48:04 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://i0.wp.com/blog.meyer-luenen.de/wp-content/uploads/2018/12/cropped-StM-Portrait-Raesfeld-600x600-removebg-2.png?fit=32%2C32&#038;ssl=1</url>
	<title>Entity Framework &#8211; Stefan Meyer</title>
	<link>https://blog.meyer-luenen.de</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">148105417</site>	<item>
		<title>Login-Seiten für MS-Identity</title>
		<link>https://blog.meyer-luenen.de/2023/12/16/login-seiten-fuer-ms-identity/</link>
		
		<dc:creator><![CDATA[Stefan]]></dc:creator>
		<pubDate>Sat, 16 Dec 2023 15:01:22 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<guid isPermaLink="false">https://blog.meyer-luenen.de/?p=708</guid>

					<description><![CDATA[aspnet-codegenerator installieren:]]></description>
										<content:encoded><![CDATA[
<p>aspnet-codegenerator installieren:</p>



<pre class="wp-block-code"><code>dotnet tool install -g dotnet-aspnet-codegenerator --version 6.0.0</code></pre>



<p></p>



<pre class="wp-block-code"><code>dotnet aspnet-codegenerator identity -dc ApplicationDbContext<br>oder wenn vorhanden:<br>dotnet aspnet-codegenerator identity -dc ApplicationDbContext --force</code></pre>



<pre class="wp-block-code"><code>dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design<br>dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design --version 6.0.0</code></pre>



<pre class="wp-block-code"><code>dotnet aspnet-codegenerator identity -dc MyBlazorApp.Data.ApplicationDbContext --files "Account.Register;Account.Login;Account.Logout"


Quelle:
<a href="https://learn.microsoft.com/de-de/aspnet/core/fundamentals/tools/dotnet-aspnet-codegenerator?view=aspnetcore-8.0" target="_blank" rel="noreferrer noopener">https://learn.microsoft.com/de-de/aspnet/core/fundamentals/tools/dotnet-aspnet-codegenerator?view=aspnetcore-8.0
</a>



</code></pre>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">708</post-id>	</item>
		<item>
		<title>EntityFramework.Core in eine .net Core Blazor WebApp integrieren</title>
		<link>https://blog.meyer-luenen.de/2023/09/02/entityframework-core-in-eine-net-core-blazor-webapp-integrieren/</link>
		
		<dc:creator><![CDATA[Stefan]]></dc:creator>
		<pubDate>Sat, 02 Sep 2023 12:20:13 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<guid isPermaLink="false">https://blog.meyer-luenen.de/?p=685</guid>

					<description><![CDATA[1. Install necessary packages: For a Blazor Server App, you&#8217;d typically manage the EF Core functionality in the Server project. So, make sure you are working in the Server project directory or set the Server project as the default project in the Package Manager Console (PMC) in Visual Studio. Using the NuGet Package Manager or [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">1. Install necessary packages:</h3>



<p>For a Blazor Server App, you&#8217;d typically manage the EF Core functionality in the Server project. So, make sure you are working in the Server project directory or set the Server project as the default project in the Package Manager Console (PMC) in Visual Studio.</p>



<p>Using the NuGet Package Manager or the PMC, install the following packages:</p>



<ul class="wp-block-list">
<li><code>Microsoft.EntityFrameworkCore</code></li>



<li><code>Microsoft.EntityFrameworkCore.SqlServer</code></li>



<li><code>Microsoft.EntityFrameworkCore.Tools</code> (for migration tools)</li>
</ul>



<h3 class="wp-block-heading">2. Define your Model:</h3>



<p>Create classes that will define the structure of your database tables. Place these in the Shared or Server project, depending on your design decisions.</p>



<p>Example:</p>



<pre class="wp-block-preformatted"><code>public class Product
{
    public int ProductId { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
}
</code></pre>



<h3 class="wp-block-heading">3. Create a DbContext:</h3>



<p>In the Server project, create a class that derives from <code>DbContext</code>:</p>



<pre class="wp-block-preformatted"><code>public class AppDbContext : DbContext
{
    public AppDbContext(DbContextOptions&lt;AppDbContext&gt; options) : base(options) { }

    public DbSet&lt;Product&gt; Products { get; set; }
}
</code></pre>



<h3 class="wp-block-heading">4. Configure the Connection String:</h3>



<p>In the <code>appsettings.json</code> file in the Server project, add your connection string:</p>



<pre class="wp-block-preformatted"><code>{
  "ConnectionStrings": {
    "DefaultConnection": "</code>Server=Servername;Database=DatabaseName;user=UserId;password=secret;MultipleActiveResultSets=true;TrustServerCertificate=True;MultiSubnetFailover=True<code>"
  }
}
</code></pre>



<p>Replace <code>YourConnectionStringHere</code> with your MS SQL Server 2022 connection string.</p>



<h3 class="wp-block-heading">5. Register DbContext:</h3>



<p>In the <code>Startup.cs</code> (or <code>Program.cs</code> for newer versions) of your Server project, register the <code>DbContext</code> in the <code>ConfigureServices</code> method:</p>



<pre class="wp-block-code"><code>builder.<code>Services.AddDbContext&lt;AppDbContext>(options =><br>    options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));</code></code></pre>



<p>(Do not forget to import EF Core)</p>



<h3 class="wp-block-heading">6. Create Initial Migration:</h3>



<p>In the PMC or terminal, navigate to the Server project directory and run:</p>



<pre class="wp-block-preformatted"><code>Add-Migration InitialCreate
</code></pre>



<p>This will scaffold a migration to create the initial set of tables for your model.</p>



<h3 class="wp-block-heading">7. Update the Database:</h3>



<p>Apply the migration to create the database schema:</p>



<pre class="wp-block-preformatted"><code>Update-Database
</code></pre>



<pre class="wp-block-preformatted"><code>
</code></pre>



<h3 class="wp-block-heading">8. Use the DbContext in your app:</h3>



<p>Now you can inject and use your <code>DbContext</code> in your pages, components, or services:</p>



<pre class="wp-block-preformatted">csharpCopy code<code>@inject AppDbContext _context

// ...

var products = await _context.Products.ToListAsync();
</code></pre>



<p>That&#8217;s the basic setup! As your app grows, you might add more entities, relationships, migrations, and other advanced EF Core features. Ensure you understand concepts like the lifecycle of a DbContext and how it tracks changes to entities to avoid issues when manipulating data.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">685</post-id>	</item>
		<item>
		<title>Entity Framework Package Manager Console Befehle</title>
		<link>https://blog.meyer-luenen.de/2021/01/30/entity-framework-package-manager-console-befehle/</link>
		
		<dc:creator><![CDATA[Stefan]]></dc:creator>
		<pubDate>Sat, 30 Jan 2021 13:39:42 +0000</pubDate>
				<category><![CDATA[Entity Framework]]></category>
		<guid isPermaLink="false">http://blog.meyer-luenen.de/?p=390</guid>

					<description><![CDATA[Erinnerungshilfe über die PM-Befehle]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code>Add-Migration InitialCreate
Update-Database
Remove-Migration
Update-Database LastGoodMigration
Script-Migration</code></pre>



<p></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">390</post-id>	</item>
	</channel>
</rss>
