﻿<?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>Veri Tabanı Tablosundan Entity Class Oluşturma &#8211; SQL Server Eğitimleri</title>
	<atom:link href="https://sqlserveregitimleri.com/etiket/veri-tabani-tablosundan-entity-class-olusturma/feed" rel="self" type="application/rss+xml" />
	<link>https://sqlserveregitimleri.com</link>
	<description>SQL Server ile ilgili her şey</description>
	<lastBuildDate>Mon, 13 Jun 2022 20:15:09 +0000</lastBuildDate>
	<language>tr</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.1</generator>
	<item>
		<title>SQL Server&#8217;da Veri Tabanı Tablosundan Entity Class Oluşturma</title>
		<link>https://sqlserveregitimleri.com/sql-serverda-veri-tabani-tablosundan-entity-class-olusturma</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Thu, 14 Apr 2022 14:43:52 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Entity Class Oluşturma]]></category>
		<category><![CDATA[SQL Entity Class Oluşturma]]></category>
		<category><![CDATA[Veri Tabanı Tablosundan Entity Class Oluşturma]]></category>
		<guid isPermaLink="false">https://sqlserveregitimleri.com/?p=13570</guid>

					<description><![CDATA[Herkese merhaba, Bu yazıda SQL Server&#8217;da veri tabanı tablosundan Entity Class oluşturma ile ilgili bilgi vermeye çalışacağım. SQL Server&#8217;da bazı durumlarda veri tabanı tablosundan Entity...]]></description>
										<content:encoded><![CDATA[<p>Herkese merhaba,</p>
<p>Bu yazıda SQL Server&#8217;da veri tabanı tablosundan Entity Class oluşturma ile ilgili bilgi vermeye çalışacağım.</p>
<p>SQL Server&#8217;da bazı durumlarda veri tabanı tablosundan Entity Class oluşturmak isteyebilirsiniz.</p>
<p>Aşağıdaki kodu kullanarak siz de bu işlemi rahatlıkla yapabilirsiniz.</p>
<pre class="line-numbers"><code class="language-sql">DECLARE @TableName sysname = 'Categories';

DECLARE @Result VARCHAR(MAX) = 'public class ' + @TableName + ' 

{';

SELECT @Result = @Result + ' 

    public '     + ColumnType + NullableSign + ' ' + ColumnName + ' { get; set; } 

'
FROM
(
    SELECT REPLACE(col.name, ' ', '_') ColumnName,
           column_id ColumnId,
           CASE typ.name
               WHEN 'bigint' THEN
                   'long'
               WHEN 'binary' THEN
                   'byte[]'
               WHEN 'bit' THEN
                   'bool'
               WHEN 'char' THEN
                   'string'
               WHEN 'date' THEN
                   'DateTime'
               WHEN 'datetime' THEN
                   'DateTime'
               WHEN 'datetime2' THEN
                   'DateTime'
               WHEN 'datetimeoffset' THEN
                   'DateTimeOffset'
               WHEN 'decimal' THEN
                   'decimal'
               WHEN 'float' THEN
                   'float'
               WHEN 'image' THEN
                   'byte[]'
               WHEN 'int' THEN
                   'int'
               WHEN 'money' THEN
                   'decimal'
               WHEN 'nchar' THEN
                   'char'
               WHEN 'ntext' THEN
                   'string'
               WHEN 'numeric' THEN
                   'decimal'
               WHEN 'nvarchar' THEN
                   'string'
               WHEN 'real' THEN
                   'double'
               WHEN 'smalldatetime' THEN
                   'DateTime'
               WHEN 'smallint' THEN
                   'short'
               WHEN 'smallmoney' THEN
                   'decimal'
               WHEN 'text' THEN
                   'string'
               WHEN 'time' THEN
                   'TimeSpan'
               WHEN 'timestamp' THEN
                   'DateTime'
               WHEN 'tinyint' THEN
                   'byte'
               WHEN 'uniqueidentifier' THEN
                   'Guid'
               WHEN 'varbinary' THEN
                   'byte[]'
               WHEN 'varchar' THEN
                   'string'
               ELSE
                   'UNKNOWN_' + typ.name
           END ColumnType,
           CASE
               WHEN col.is_nullable = 1
                    AND typ.name IN ( 'bigint', 'bit', 'date', 'datetime', 'datetime2', 'datetimeoffset', 'decimal',
                                      'float', 'int', 'money', 'numeric', 'real', 'smalldatetime', 'smallint',
                                      'smallmoney', 'time', 'tinyint', 'uniqueidentifier'
                                    ) THEN
                   '?'
               ELSE
                   ''
           END NullableSign
    FROM sys.columns col
        JOIN sys.types typ
            ON col.system_type_id = typ.system_type_id
               AND col.user_type_id = typ.user_type_id
    WHERE object_id = OBJECT_ID(@TableName)
) t
ORDER BY ColumnId;

SET @Result = @Result + ' 

}';

PRINT @Result;</code></pre>
<p>Yukarıdaki kodu çalıştırdığınızda aşağıdakine benzer bir sonuç göreceksiniz.</p>
<p><img fetchpriority="high" decoding="async" class="alignnone wp-image-13573 size-full" src="https://sqlserveregitimleri.com/wp-content/uploads/2022/04/sql-serverda-veri-tabani-tablosundan-entity-class-olusturma-1.jpg" alt="SQL Server'da Veri Tabanı Tablosundan Entity Class Oluşturma" width="700" height="567" srcset="https://sqlserveregitimleri.com/wp-content/uploads/2022/04/sql-serverda-veri-tabani-tablosundan-entity-class-olusturma-1.jpg 700w, https://sqlserveregitimleri.com/wp-content/uploads/2022/04/sql-serverda-veri-tabani-tablosundan-entity-class-olusturma-1-315x255.jpg 315w, https://sqlserveregitimleri.com/wp-content/uploads/2022/04/sql-serverda-veri-tabani-tablosundan-entity-class-olusturma-1-370x300.jpg 370w, https://sqlserveregitimleri.com/wp-content/uploads/2022/04/sql-serverda-veri-tabani-tablosundan-entity-class-olusturma-1-167x135.jpg 167w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>Görüldüğü üzere veri tabanı tablosundan Entity Class oluşturulmuş oldu.</p>
<p>Herkese çalışma hayatında ve yaşamında başarılar kolaylıklar.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 244</span><span class='epvc-label'> Kez Okundu</span></div>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
