<?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; Ling&#039;s Note</title>
	<atom:link href="https://www.chunho-ling.com/category/computing/database/object-relation-mapping-orm/entityframework/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.chunho-ling.com</link>
	<description>Everything related IT, and me.</description>
	<lastBuildDate>Tue, 08 Jan 2019 09:27:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.2</generator>
<site xmlns="com-wordpress:feed-additions:1">104401516</site>	<item>
		<title>[.net Core] 解決傳回JSON 時recursion 問題</title>
		<link>https://www.chunho-ling.com/net-core-%e8%a7%a3%e6%b1%ba%e5%82%b3%e5%9b%9ejson-%e6%99%82recursion-%e5%95%8f%e9%a1%8c/</link>
					<comments>https://www.chunho-ling.com/net-core-%e8%a7%a3%e6%b1%ba%e5%82%b3%e5%9b%9ejson-%e6%99%82recursion-%e5%95%8f%e9%a1%8c/#respond</comments>
		
		<dc:creator><![CDATA[C.H. Ling]]></dc:creator>
		<pubDate>Tue, 08 Jan 2019 09:21:50 +0000</pubDate>
				<category><![CDATA[.net Core]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Object-Relation Mapping (ORM)]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">https://www.chunho-ling.com/?p=1190</guid>

					<description><![CDATA[之前在Java 遇過同樣問題, 解決方案是在getter 中加入annotation. 而在.net core 中, 則需要透過修改startup(). 在Startup.cs 中修改ConfigureService() 如下便可: public void ConfigureServices(IServiceCollection services) { services.AddMvc().AddJsonOptions(options =&#62; { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2); } &#160;]]></description>
										<content:encoded><![CDATA[<p>之前在Java 遇過同樣問題, 解決方案是在getter 中加入annotation. 而在.net core 中, 則需要透過修改startup().<span id="more-1190"></span></p>
<p>在Startup.cs 中修改ConfigureService() 如下便可:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().AddJsonOptions(options =&gt;
            {
                options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chunho-ling.com/net-core-%e8%a7%a3%e6%b1%ba%e5%82%b3%e5%9b%9ejson-%e6%99%82recursion-%e5%95%8f%e9%a1%8c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1190</post-id>	</item>
		<item>
		<title>[Entity Framework] 於查詢時移除不必要的check null where clause</title>
		<link>https://www.chunho-ling.com/entity-framework-%e6%96%bc%e6%9f%a5%e8%a9%a2%e6%99%82%e7%a7%bb%e9%99%a4%e4%b8%8d%e5%bf%85%e8%a6%81%e7%9a%84check-null-where-clause/</link>
					<comments>https://www.chunho-ling.com/entity-framework-%e6%96%bc%e6%9f%a5%e8%a9%a2%e6%99%82%e7%a7%bb%e9%99%a4%e4%b8%8d%e5%bf%85%e8%a6%81%e7%9a%84check-null-where-clause/#respond</comments>
		
		<dc:creator><![CDATA[C.H. Ling]]></dc:creator>
		<pubDate>Fri, 12 Jan 2018 03:55:45 +0000</pubDate>
				<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Object-Relation Mapping (ORM)]]></category>
		<guid isPermaLink="false">http://www.chunho-ling.com/?p=809</guid>

					<description><![CDATA[有時當進行performance tuning 時, 有時會在ORM 層面遇到問題. 檢查記錄後, 發覺原來透過Entity Framework 將LINQ 或Lambla express 轉換成SQL 時會出產生了不必要的Check null, 從而使Index 不能觸發, 亦因此令執行時間變長. 要解決的話, 只須在DbContext 中Disable 其設定便可. public class DataContext : DbContext { public DataContext() { this.Configuration.UseDatabaseNullSemantics = true; } } <a class="mh-excerpt-more" href="https://www.chunho-ling.com/entity-framework-%e6%96%bc%e6%9f%a5%e8%a9%a2%e6%99%82%e7%a7%bb%e9%99%a4%e4%b8%8d%e5%bf%85%e8%a6%81%e7%9a%84check-null-where-clause/" title="[Entity Framework] 於查詢時移除不必要的check null where clause">[...]</a>]]></description>
										<content:encoded><![CDATA[<p>有時當進行performance tuning 時, 有時會在ORM 層面遇到問題. 檢查記錄後, 發覺原來透過Entity Framework 將LINQ 或Lambla express 轉換成SQL 時會出產生了不必要的Check null, 從而使Index 不能觸發, 亦因此令執行時間變長.</p>
<p><span id="more-809"></span>要解決的話, 只須在DbContext 中Disable 其設定便可.</p>
<pre class="lang:default decode:true ">public class DataContext : DbContext
{
    public DataContext()
    {
        this.Configuration.UseDatabaseNullSemantics = true;
    }
}</pre>
<p>參考資料</p>
<ul>
<li>DbContextConfiguration.UseDatabaseNullSemantics Property, MSDN, <a href="https://msdn.microsoft.com/en-us/library/system.data.entity.infrastructure.dbcontextconfiguration.usedatabasenullsemantics(v=vs.113).aspx" target="_blank" rel="noopener">https://msdn.microsoft.com/en-us/library/system.data.entity.infrastructure.dbcontextconfiguration.usedatabasenullsemantics(v=vs.113).aspx</a></li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chunho-ling.com/entity-framework-%e6%96%bc%e6%9f%a5%e8%a9%a2%e6%99%82%e7%a7%bb%e9%99%a4%e4%b8%8d%e5%bf%85%e8%a6%81%e7%9a%84check-null-where-clause/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">809</post-id>	</item>
		<item>
		<title>[Entity Framework] 如何加入SQL server Function</title>
		<link>https://www.chunho-ling.com/entity-framework-%e5%a6%82%e4%bd%95%e5%8a%a0%e5%85%a5sql-server-function/</link>
					<comments>https://www.chunho-ling.com/entity-framework-%e5%a6%82%e4%bd%95%e5%8a%a0%e5%85%a5sql-server-function/#respond</comments>
		
		<dc:creator><![CDATA[C.H. Ling]]></dc:creator>
		<pubDate>Wed, 02 Nov 2016 09:35:20 +0000</pubDate>
				<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">http://www.chunho-ling.com/?p=155</guid>

					<description><![CDATA[有時寫code時, 有需要call 到SQL server 內的Function 但卻不能順利進行. 除了DataContext.ExecuteCommand()進行外, 還可以透過DbFunctionAttribute使用. 使用時EntityFramework 會直接call SQL server function 並return 其value. [DbFunction("hkcfDataModel.Store", "GetDonorName")] public string GetDonorName(string nvchCompanyName, string nvchTcFirstName, string nvchTcLastName, string nvchTcPrefix, string vchEnFirstName, string vchEnLastName, string vchEnPrefix, string vchLang) <a class="mh-excerpt-more" href="https://www.chunho-ling.com/entity-framework-%e5%a6%82%e4%bd%95%e5%8a%a0%e5%85%a5sql-server-function/" title="[Entity Framework] 如何加入SQL server Function">[...]</a>]]></description>
										<content:encoded><![CDATA[<p>有時寫code時, 有需要call 到SQL server 內的Function 但卻不能順利進行. 除了DataContext.ExecuteCommand()進行外, 還可以透過DbFunctionAttribute使用.</p>
<p><span id="more-155"></span>使用時EntityFramework 會直接call SQL server function 並return 其value.</p>
<pre class="lang:c# decode:true " title="DbFunctionExmaple">[DbFunction("hkcfDataModel.Store", "GetDonorName")]
public string GetDonorName(string nvchCompanyName, string nvchTcFirstName, string nvchTcLastName, string nvchTcPrefix, string vchEnFirstName, string vchEnLastName, string vchEnPrefix, string vchLang)
{
    throw new NotSupportedException("Direct call does not supported.");
}</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chunho-ling.com/entity-framework-%e5%a6%82%e4%bd%95%e5%8a%a0%e5%85%a5sql-server-function/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">155</post-id>	</item>
		<item>
		<title>[EntityFramework] 如何cascade insert</title>
		<link>https://www.chunho-ling.com/entityframework-%e5%a6%82%e4%bd%95cascade-insert/</link>
					<comments>https://www.chunho-ling.com/entityframework-%e5%a6%82%e4%bd%95cascade-insert/#respond</comments>
		
		<dc:creator><![CDATA[C.H. Ling]]></dc:creator>
		<pubDate>Tue, 22 Mar 2016 07:54:20 +0000</pubDate>
				<category><![CDATA[Entity Framework]]></category>
		<guid isPermaLink="false">http://www.chunho-ling.com/?p=119</guid>

					<description><![CDATA[當在create model 時, 有機會assign value 到其相對應的class中之後做insert 動作. 但若在ORM 層面的話, 須要在所有child item inserted 後才可進行, 否則有機會throw exception. 為了應對這問題, 可以用以下方法做work-around: using (NotificationEntities entites = new NotificationEntities()) { entites.EMAILs.Add(email); entites.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[EMAIL] ON"); entites.SaveChanges(); entites.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[EMAIL] OFF"); } <a class="mh-excerpt-more" href="https://www.chunho-ling.com/entityframework-%e5%a6%82%e4%bd%95cascade-insert/" title="[EntityFramework] 如何cascade insert">[...]</a>]]></description>
										<content:encoded><![CDATA[<p>當在create model 時, 有機會assign value 到其相對應的class中之後做insert 動作. 但若在ORM 層面的話, 須要在所有child item inserted 後才可進行, 否則有機會throw exception. 為了應對這問題, 可以用以下方法做work-around:</p>
<pre class="lang:c# decode:true "> using (NotificationEntities entites = new NotificationEntities())
                {
 entites.EMAILs.Add(email);
                    entites.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[EMAIL] ON");
                    entites.SaveChanges();
                    entites.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[EMAIL] OFF");
}</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.chunho-ling.com/entityframework-%e5%a6%82%e4%bd%95cascade-insert/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">119</post-id>	</item>
	</channel>
</rss>
