<?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>Benjamin Devuyst &#187; Entity Framework</title>
	<atom:link href="https://blog.developpez.com/bdevuyst/pcategory/dotnet-net/entity-framework/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/bdevuyst</link>
	<description>:)</description>
	<lastBuildDate>Mon, 16 Mar 2020 06:57:16 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Initialiser les données d&#8217;une base de données avec Entity Framework 5</title>
		<link>https://blog.developpez.com/bdevuyst/p11296/dotnet-net/initialiser-les-donnees-dune-base-de-donnees-avec-entity-framework-5</link>
		<comments>https://blog.developpez.com/bdevuyst/p11296/dotnet-net/initialiser-les-donnees-dune-base-de-donnees-avec-entity-framework-5#comments</comments>
		<pubDate>Mon, 10 Sep 2012 18:42:28 +0000</pubDate>
		<dc:creator><![CDATA[benji_dv]]></dc:creator>
				<category><![CDATA[DotNet - .net]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[base de données]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[données]]></category>
		<category><![CDATA[initialisation]]></category>
		<category><![CDATA[seeding]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/bdevuyst/?p=44</guid>
		<description><![CDATA[Un tweet ma indiqué ce blog qui traite d&#8217;une fonctionnalité de datant seeding Intéressant ! http://odetocode.com/Blogs/scott/archive/2012/08/31/seeding-an-entity-framework-database-from-file-data.aspx]]></description>
				<content:encoded><![CDATA[<p>Un tweet ma indiqué ce blog qui traite d&rsquo;une fonctionnalité de datant seeding<br />
Intéressant !<br />
<a href="http://odetocode.com/Blogs/scott/archive/2012/08/31/seeding-an-entity-framework-database-from-file-data.aspx" title="http://odetocode.com/Blogs/scott/archive/2012/08/31/seeding-an-entity-framework-database-from-file-data.aspx" target="_blank">http://odetocode.com/Blogs/scott/archive/2012/08/31/seeding-an-entity-framework-database-from-file-data.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entity Framework 4 + Timeout expired : tout un programme !</title>
		<link>https://blog.developpez.com/bdevuyst/p10676/dotnet-net/entity_framework_4_timeout_expired</link>
		<comments>https://blog.developpez.com/bdevuyst/p10676/dotnet-net/entity_framework_4_timeout_expired#comments</comments>
		<pubDate>Thu, 26 Jan 2012 12:50:11 +0000</pubDate>
		<dc:creator><![CDATA[benji_dv]]></dc:creator>
				<category><![CDATA[DotNet - .net]]></category>
		<category><![CDATA[Entity Framework]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Un jour, un client fut confronté à ceci : &#171;&#160;Entity Framework and Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.&#160;&#187; Explicite ! non ? La solution : Paramétrer le Command Timeout de l&#8217;object context &#8230; var ctx = new DataContext() { CommandTimeout = 90 }; // DataContext est ma classe context EF Du coup, le temps d&#8217;exécution des commandes SQL passe à 90 secondes (au [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Un jour, un client fut confronté à ceci :<br />
&laquo;&nbsp;Entity Framework and Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.&nbsp;&raquo;</p>
<p>Explicite ! non ?</p>
<p>La solution : Paramétrer le Command Timeout de l&rsquo;object context &#8230;</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var ctx = new DataContext() { CommandTimeout = 90 }; // DataContext est ma classe context EF</div></div>
<p>Du coup, le temps d&rsquo;exécution des commandes SQL passe à 90 secondes (au lieu des 30 secondes par défaut).</p>
<p>Pour information : il est conseillé de rendre cette valeur paramétrable (config)&#8230;</p>
<p><a href="http://msdn.microsoft.com/fr-fr/library/system.data.objects.objectcontext.commandtimeout.aspx">http://msdn.microsoft.com/fr-fr/library/system.data.objects.objectcontext.commandtimeout.aspx</a></p>
<p>Voilou !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entity Framework 4 + Group By + Include</title>
		<link>https://blog.developpez.com/bdevuyst/p10500/dotnet-net/entity_framework_4_include_group_by</link>
		<comments>https://blog.developpez.com/bdevuyst/p10500/dotnet-net/entity_framework_4_include_group_by#comments</comments>
		<pubDate>Tue, 15 Nov 2011 09:19:06 +0000</pubDate>
		<dc:creator><![CDATA[benji_dv]]></dc:creator>
				<category><![CDATA[DotNet - .net]]></category>
		<category><![CDATA[Entity Framework]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Imaginons la requête EF suivante : ctx.ContextOptions.LazyLoadingEnabled = false; var cmds = ctx.Commande .Include(&#171;&#160;DetailCommande&#160;&#187;) .Where(cmd=>&#8230;filtre&#8230;) .GroupBy(cmd=>cmd.date) .OrderBy(cmd=>cmd.Key) .FirstOrDefault(); Cette requête va me retourner la première commande par jour en fonction d&#8217;un filtre. Qu&#8217;importe l&#8217;intérêt fonctionnel (certainement débile :p ), centrons nous sur le résultat : L&#8217;include est royalement nié : aucun détail de commande n&#8217;est présent dans les éléments retournés, malgré la clause Include. Une solution possible (mais il y en a d&#8217;autres) : Retourner [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Imaginons la requête EF suivante :</p>
<p>ctx.ContextOptions.LazyLoadingEnabled = false;</p>
<p>var cmds =<br />
 ctx.Commande<br />
 .Include(&laquo;&nbsp;DetailCommande&nbsp;&raquo;)<br />
 .Where(cmd=>&#8230;filtre&#8230;)<br />
 .GroupBy(cmd=>cmd.date)<br />
 .OrderBy(cmd=>cmd.Key)<br />
 .FirstOrDefault();</p>
<p>Cette requête va me retourner la première commande par jour en fonction d&rsquo;un filtre.<br />
Qu&rsquo;importe l&rsquo;intérêt fonctionnel (certainement débile :p ), centrons nous sur le résultat :<br />
L&rsquo;include est royalement nié : aucun détail de commande n&rsquo;est présent dans les éléments retournés, malgré la clause Include.</p>
<p>Une solution possible (mais il y en a d&rsquo;autres) :</p>
<ul>
<li>
<strong>Retourner les ids de commande concernés :</strong><br />
var ids =<br />
 ctx.Commande<br />
 .Where(cmd => &#8230;filtre&#8230;)<br />
 .GroupBy(cmd => cmd.date)<br />
 .OrderBy(cmd => cmd.Key)<br />
 .FirstOrDefault().Select(cmd => cmd.Id);
</li>
<li>
<strong>Récupérer les commandes avec l&rsquo;include :</strong><br />
var cmds =<br />
 ctx.Commande<br />
 .Include(&laquo;&nbsp;DetailCommande&nbsp;&raquo;)<br />
 .Where(cmd => ids.Contains(cmd.Id)).ToList();</p>
<p>PS : le ToList est là pour forcer l&rsquo;exécution (vu que le LazyLoading est à false)
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entity framework, les objets complexes et nombreux</title>
		<link>https://blog.developpez.com/bdevuyst/p10098/dotnet-net/entity_framework_les_objets_complexes_et</link>
		<comments>https://blog.developpez.com/bdevuyst/p10098/dotnet-net/entity_framework_les_objets_complexes_et#comments</comments>
		<pubDate>Wed, 29 Jun 2011 13:24:16 +0000</pubDate>
		<dc:creator><![CDATA[benji_dv]]></dc:creator>
				<category><![CDATA[DotNet - .net]]></category>
		<category><![CDATA[Entity Framework]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Dans notre application du jour, nous manipulons l?insertion de graphes d?objets. Le graphe s?étend sur 5 niveaux de profondeurs et est constitué de 32 noeuds (donc 32 classes). Afin d?assurer la cohérence des mises à jour de la base de données, nous utilisons des objets ?TransactionScope?. Lors de l?insertion (ou de la mise à jour) de plus de 3000 objets simultanément, nous avons rencontré des exceptions telles que ?La transaction associée à la connexion active [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Dans notre application du jour, nous manipulons l?insertion de graphes d?objets. Le graphe s?étend sur 5 niveaux de profondeurs et est constitué de 32 noeuds (donc 32 classes).</p>
<p>Afin d?assurer la cohérence des mises à jour de la base de données, nous utilisons des objets ?TransactionScope?.</p>
<p>Lors de l?insertion (ou de la mise à jour) de plus de 3000 objets simultanément, nous avons rencontré des exceptions telles que    <br />?La transaction associée à la connexion active est terminée mais n&rsquo;a pas été supprimée. Pour pouvoir utiliser la transaction pour exécuter des instructions SQL vous devez la supprimer.?     <br />ce que l?on peut traduire en     <br />?The transaction associated with the current connection has completed but has not been disposed. The transaction must be disposed before the connection can be used to execute SQL statements.?     <br />(merci <a href="http://www.unlocalize.com">http://www.unlocalize.com</a>)</p>
<p>La solution demeure assez simple :</p>
<p>il suffit de passer de </p>
<div style="background-color: white; color: black"><span style="color: blue">using</span> (<span style="color: blue">var</span> transaction = <span style="color: blue">new</span> <font color="#0fb0bd">TransactionScope</font>()) </div>
<div style="background-color: white; color: black">{ </div>
<div style="background-color: white; color: black">   <span style="color: gray">///</span><span style="color: green">/ Code de mise à jour de la base de données</span> </div>
<div style="background-color: white; color: black">   transaction.Complete();</div>
<div style="background-color: white; color: black">} </div>
<p>à</p>
<div style="background-color: white; color: black"><span style="color: blue">using</span> (<span style="color: blue">var</span> transaction = <span style="color: blue">new</span> <font color="#0fb0bd">TransactionScope</font>(</div>
<div style="background-color: white; color: black">                                          <font color="#0fb0bd">TransactionScopeOption</font>.<font color="#0fb0bd">Required</font>,</div>
<div style="background-color: white; color: black">                                          <span style="color: blue">new</span> <font color="#0fb0bd">TransactionOptions</font>() </div>
<div style="background-color: white; color: black">                                          { </div>
<div style="background-color: white; color: black">                                             IsolationLevel = <font color="#0fb0bd">System.Transactions.IsolationLevel.Serializable</font>, </div>
<div style="background-color: white; color: black">                                             Timeout = TimeSpan.FromSeconds(120) </div>
<div style="background-color: white; color: black">                                          })) </div>
<div style="background-color: white; color: black">{ </div>
<div style="background-color: white; color: black">   <span style="color: gray">///</span><span style="color: green">/ Code de mise à jour de la base de données</span> </div>
<div style="background-color: white; color: black">   transaction.Complete(); </div>
<div style="background-color: white; color: black">} </div>
<p>Pour information : <a href="https://connect.microsoft.com/VisualStudio/feedback/details/564598/ef-connection-brokes-when-sending-large-amount-of-data-in-transactionscope#tabs">https://connect.microsoft.com/VisualStudio/feedback/details/564598/ef-connection-brokes-when-sending-large-amount-of-data-in-transactionscope#tabs</a></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Entity Framework et les CLR UDF (User Defined Functions) d’agrégation sous SQL Server</title>
		<link>https://blog.developpez.com/bdevuyst/p10010/dotnet-net/ef4_udf_linq_ef_fonction_agregation</link>
		<comments>https://blog.developpez.com/bdevuyst/p10010/dotnet-net/ef4_udf_linq_ef_fonction_agregation#comments</comments>
		<pubDate>Tue, 24 May 2011 10:21:39 +0000</pubDate>
		<dc:creator><![CDATA[benji_dv]]></dc:creator>
				<category><![CDATA[DotNet - .net]]></category>
		<category><![CDATA[Entity Framework]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Nous travaillons sur un projet qui exploite : un modèle Entity Framework au sein d’une couche d’accès aux données, des CLR UDF (user defined functions) permettant l’agrégation de données (comme SUM, AVG, etc). Pour information, ce sont des assemblies dot net injecté dans SQL Server permettant de disposer de fonctionnalités dot net appelable à partir de code SQL directement, comme si ces fonctions étaient natives à SQL Server), Nous avons été confrontés à la nécessité [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Nous travaillons sur un projet qui exploite :</p>
<ul>
<li>un modèle Entity Framework au sein d’une couche d’accès aux données, </li>
<li>des CLR UDF (user defined functions) permettant l’agrégation de données (comme SUM, AVG, etc).<br />
    <br />Pour information, ce sont des assemblies dot net injecté dans SQL Server permettant de disposer de fonctionnalités dot net appelable à partir de code SQL directement, comme si ces fonctions étaient natives à SQL Server), </li>
</ul>
<p>Nous avons été confrontés à la nécessité de devoir utiliser ces CLR-UDF(disponibles en SQL mais, pas nativement en C#) d’agrégation dans la DAL de l’application, via les requêtes Linq sur le modèle EF.</p>
<p>Nativement… ce n’est pas possible.</p>
<p>Il faut modifier le cours des choses… <img src="https://blog.developpez.com/bdevuyst/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /> </p>
<p>Recette :</p>
<ul>
<li>Modifier l’edmx pour ajouter la fonction </li>
<li>Ajouter une classe particulière au sein du projet, pour permettre à Linq-EF de connaitre la fonction </li>
<li>Utiliser la fonction dans les requêtes Linq-EF </li>
</ul>
<h2>Modification de l’EDMX</h2>
<p>Voici les fonctions d’agrégations disponibles sous SQL Server : </p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.developpez.com/media/EF4-AggregatesFct01.png" width="231" height="244" /></p>
<p>Ouvrir l’edmx dans le designer, et appeler le menu contextuel pour mettre à jour le modèle, ajouter la fonction (située dans les procédures stoquées…), en jaune ci dessous…</p>
<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.developpez.com/media/EF4-AggregatesFct02.png" width="371" height="330" /></p>
<p>Valider en cliquant sur Terminer.</p>
<p>Ouvrer l’Edmx à la main (éditeur XML), à la recherche des fonctions d’agrégation ajoutées (<span style="color: blue">InterpWeightAvg</span> et <span style="color: blue">InterpWeightSum</span>):</p>
<div style="background-color: white; color: black">
<div style="background-color: white; color: black">
<pre><span style="color: blue">&lt;</span><span style="color: #a31515">Function</span> <span style="color: red">Name</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">InterpWeightAvg</span><span style="color: black">&quot;</span> <span style="color: red">ReturnType</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">float</span><span style="color: black">&quot;</span> <span style="color: red">Aggregate</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">false</span><span style="color: black">&quot;</span> 
          <span style="color: red">BuiltIn</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">false</span><span style="color: black">&quot;</span> <span style="color: red">NiladicFunction</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">false</span><span style="color: black">&quot;</span> <span style="color: red">IsComposable</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">true</span><span style="color: black">&quot;</span> 
          <span style="color: red">ParameterTypeSemantics</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">AllowImplicitConversion</span><span style="color: black">&quot;</span> <span style="color: red">Schema</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">dbo</span><span style="color: black">&quot;</span><span style="color: blue">&gt;</span>
	<span style="color: blue">&lt;</span><span style="color: #a31515">Parameter</span> <span style="color: red">Name</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">value</span><span style="color: black">&quot;</span> <span style="color: red">Type</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">float</span><span style="color: black">&quot;</span> <span style="color: red">Mode</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">In</span><span style="color: black">&quot;</span> <span style="color: blue">/&gt;</span>
<span style="color: blue">&lt;/</span><span style="color: #a31515">Function</span><span style="color: blue">&gt;</span>
<span style="color: blue">&lt;</span><span style="color: #a31515">Function</span> <span style="color: red">Name</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">InterpWeightSum</span><span style="color: black">&quot;</span> <span style="color: red">ReturnType</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">float</span><span style="color: black">&quot;</span> <span style="color: red">Aggregate</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">false</span><span style="color: black">&quot;</span> 
          <span style="color: red">BuiltIn</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">false</span><span style="color: black">&quot;</span> <span style="color: red">NiladicFunction</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">false</span><span style="color: black">&quot;</span> <span style="color: red">IsComposable</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">true</span><span style="color: black">&quot;</span> 
          <span style="color: red">ParameterTypeSemantics</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">AllowImplicitConversion</span><span style="color: black">&quot;</span> <span style="color: red">Schema</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">dbo</span><span style="color: black">&quot;</span><span style="color: blue">&gt;</span>
	<span style="color: blue">&lt;</span><span style="color: #a31515">Parameter</span> <span style="color: red">Name</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">value</span><span style="color: black">&quot;</span> <span style="color: red">Type</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">float</span><span style="color: black">&quot;</span> <span style="color: red">Mode</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">In</span><span style="color: black">&quot;</span> <span style="color: blue">/&gt;</span>
<span style="color: blue">&lt;/</span><span style="color: #a31515">Function</span><span style="color: blue">&gt;</span></pre>
</p></div>
<div style="background-color: white; color: black">Modifier l’attribut <span style="color: red">Aggregate </span>: changer la valeur de <span style="color: blue">false </span>à <span style="color: blue">true</span>. </div>
<div style="background-color: white; color: black">Modifier le type des paramètres, de <span style="color: blue">float</span> à <span style="color: blue">Collection(float)</span>. Ceci est nécessaire : une fonction d’agrégation prend n données en entrée ! </p>
<p>&#160;</div>
<div style="background-color: white; color: black">Le résultat correspond donc à ceci :</div>
<div style="background-color: white; color: black">
<pre><span style="color: blue">&lt;</span><span style="color: #a31515">Function</span> <span style="color: red">Name</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">InterpWeightAvg</span><span style="color: black">&quot;</span> <span style="color: red">ReturnType</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">float</span><span style="color: black">&quot;</span> <span style="color: red">Aggregate</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">true</span><span style="color: black">&quot;</span> 
          <span style="color: red">BuiltIn</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">false</span><span style="color: black">&quot;</span> <span style="color: red">NiladicFunction</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">false</span><span style="color: black">&quot;</span> <span style="color: red">IsComposable</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">true</span><span style="color: black">&quot;</span> 
<span style="color: red">          ParameterTypeSemantics</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">AllowImplicitConversion</span><span style="color: black">&quot;</span> <span style="color: red">Schema</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">dbo</span><span style="color: black">&quot;</span><span style="color: blue">&gt;</span>
	<span style="color: blue">&lt;</span><span style="color: #a31515">Parameter</span> <span style="color: red">Name</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">value</span><span style="color: black">&quot;</span> <span style="color: red">Type</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">Collection(float)</span><span style="color: black">&quot;</span> <span style="color: red">Mode</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">In</span><span style="color: black">&quot;</span> <span style="color: blue">/&gt;</span>
<span style="color: blue">&lt;/</span><span style="color: #a31515">Function</span><span style="color: blue">&gt;</span>
<span style="color: blue">&lt;</span><span style="color: #a31515">Function</span> <span style="color: red">Name</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">InterpWeightSum</span><span style="color: black">&quot;</span> <span style="color: red">ReturnType</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">float</span><span style="color: black">&quot;</span> <span style="color: red">Aggregate</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">true</span><span style="color: black">&quot;</span> <br />          <span style="color: red">BuiltIn</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">false</span><span style="color: black">&quot;</span> <span style="color: red">NiladicFunction</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">false</span><span style="color: black">&quot;</span> <span style="color: red">IsComposable</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">true</span><span style="color: black">&quot;</span> <br />          <span style="color: red">ParameterTypeSemantics</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">AllowImplicitConversion</span><span style="color: black">&quot;</span> <span style="color: red">Schema</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">dbo</span><span style="color: black">&quot;</span><span style="color: blue">&gt;</span>
	<span style="color: blue">&lt;</span><span style="color: #a31515">Parameter</span> <span style="color: red">Name</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">value</span><span style="color: black">&quot;</span> <span style="color: red">Type</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">Collection(float)</span><span style="color: black">&quot;</span> <span style="color: red">Mode</span><span style="color: blue">=</span><span style="color: black">&quot;</span><span style="color: blue">In</span><span style="color: black">&quot;</span> <span style="color: blue">/&gt;</span>
<span style="color: blue">&lt;/</span><span style="color: #a31515">Function</span><span style="color: blue">&gt;</span></pre>
</p></div>
</div>
<h2>Ajout d’une classe de mapping sur la fonction</h2>
<p>L’étape ultime consiste à créer une classe d’extension, sur les types manipulés pour permettre la liaison avec la fonction d’agrégation.</p>
<div style="background-color: white; color: black">
<pre><span style="color: blue">    public</span> <span style="color: blue">static</span> <span style="color: blue">class</span> LinqAggregatesMapper
    {
        [EdmFunction(<span style="color: #a31515">&quot;MyEntityModel.Store&quot;</span>, <span style="color: #a31515">&quot;InterpWeightAvg&quot;</span>)]
        <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">double</span>? InterpWeightAvg(<span style="color: blue">this</span> IEnumerable&lt;<span style="color: blue">double</span>?&gt; source)
        {
            <span style="color: blue">throw</span> <span style="color: blue">new</span> NotImplementedException(<span style="color: #a31515">&quot;Direct calls are not supported.&quot;</span>);
        }

        [EdmFunction(<span style="color: #a31515">&quot;MyEntityModel.Store&quot;</span>, <span style="color: #a31515">&quot;InterpWeightAvg&quot;</span>)]
        <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">double</span>? InterpWeightAvg(<span style="color: blue">this</span> IEnumerable&lt;<span style="color: blue">double</span>&gt; source)
        {
            <span style="color: blue">throw</span> <span style="color: blue">new</span> NotImplementedException(<span style="color: #a31515">&quot;Direct calls are not supported.&quot;</span>);
        }</pre>
<pre>        [EdmFunction(<span style="color: #a31515">&quot;MyEntityModel.Store&quot;</span>, <span style="color: #a31515">&quot;InterpWeightSum&quot;</span>)] <br />        <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">double</span>? InterpWeightSum(<span style="color: blue">this</span> IEnumerable&lt;<span style="color: blue">double</span>&gt; source) <br />        { <br />            <span style="color: blue">throw</span> <span style="color: blue">new</span> NotImplementedException(<span style="color: #a31515">&quot;Direct calls are not supported.&quot;</span>); <br />        }<br />       <br />        [EdmFunction(<span style="color: #a31515">&quot;MyEntityModel.Store&quot;</span>, <span style="color: #a31515">&quot;InterpWeightSum&quot;</span>)] <br />        <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">double</span>? InterpWeightSum(<span style="color: blue">this</span> IEnumerable&lt;<span style="color: blue">double</span>&gt; source) <br />        { <br />            <span style="color: blue">throw</span> <span style="color: blue">new</span> NotImplementedException(<span style="color: #a31515">&quot;Direct calls are not supported.&quot;</span>); <br />        }<br /><br /><br /><br />    }</pre>
</div>
<p>J’attire votre attention sur les points suivants :</p>
<ul>
<li>La classe est statique (normal =&gt; classe d’extension), </li>
<li>L’utilisation du mot clé “this” (normal =&gt; méthode d’extension), </li>
<li>Chaque fonction est décorée par un attribut “EdmFunction”. Cet attribut précise en premier paramètre le chemin (namespace) de la fonction dans l’edmx (nom du contexte de données + Store =&gt; indique le SSDL), le second paramètre précise le nom de la fonction dans le SSDL, </li>
<li>Chaque fonction est doublée : type nullable et non nullable (indispensable), </li>
</ul>
<h2>Utilisation de la fonction dans Linq-EF</h2>
<p>Exemple d’utilisation dans notre code :</p>
<div style="background-color: white; color: black">
<pre><span style="color: blue">var</span> result = context.DonneeDetaillees.Select(data =&gt; data.DureeFonctionnement).<span style="background-color: #ffff00">InterpolateAvg();</span></pre>
</div>
<p>En ouvrant le SQL Profiler (mais on peut également utiliser l’intellitrace de Visual Studio), il devient possible de voir dans la requête SQL générée l’utilisation de la fonction.</p>
<p><strong>Attention tout de même :</strong> nous avons noté que lors de mises à jour de l’Edmx par le designer de Visual Studio, il arrivait que notre modification manuelle de la fonction soit à nouveau ré écrite par le designer.</p>
<p>Bonne journée <img src="https://blog.developpez.com/bdevuyst/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /> </p>
<p>Merci à l’équipe : Xavier et David.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entity Framework 4 : “ An item with the same key has already been added “ lors de la mise à jour de l’ EDMX …</title>
		<link>https://blog.developpez.com/bdevuyst/p9988/dotnet-net/entity_framework_4_aldquo_an_item_with_t</link>
		<comments>https://blog.developpez.com/bdevuyst/p9988/dotnet-net/entity_framework_4_aldquo_an_item_with_t#comments</comments>
		<pubDate>Thu, 19 May 2011 09:19:19 +0000</pubDate>
		<dc:creator><![CDATA[benji_dv]]></dc:creator>
				<category><![CDATA[DotNet - .net]]></category>
		<category><![CDATA[Entity Framework]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Un petit post sur Entity Framework (encore un, certe), ou plutôt sur le designer EDMX de Visual Studio. Il semblerait qu?un disfonctionnement vienne parfois troubler la sérialisation du modèle contenu dans l&#8217; edmx. Hier soir (mais qu&#8217;importe, cela ne change pas le problème ), nous avons tenté la mise à jour du modèle. Et, comment ??? mais qu&#8217;est ce que j&#8217;apprends ??! &#8230; pas très explicite &#8230; Après recherche dans l&#8217;edmx , partie mapping (msl, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Un petit post sur Entity Framework (encore un, certe), ou plutôt sur le designer EDMX de Visual Studio.</p>
<p>Il semblerait qu?un disfonctionnement vienne parfois troubler la sérialisation du modèle contenu dans l&rsquo; edmx.</p>
<p>Hier soir (mais qu&rsquo;importe, cela ne change pas le problème <img style="border-bottom-style: none; border-right-style: none; border-top-style: none; border-left-style: none" class="wlEmoticon wlEmoticon-smile" alt="Sourire" src="http://blog.developpez.com/media/333/wlEmoticon-smile.png" /> ), nous avons tenté la mise à jour du modèle.</p>
<p>Et, comment ??? mais qu&rsquo;est ce que j&rsquo;apprends ??!</p>
<p><a href="http://blog.developpez.com/media/333/EF4-EDMX-DESIGNER-BUG.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="EF4-EDMX-DESIGNER-BUG" border="0" alt="EF4-EDMX-DESIGNER-BUG" src="http://blog.developpez.com/media/333/EF4-EDMX-DESIGNER-BUG_thumb.png" width="475" height="181" /></a></p>
<p>&#8230; pas très explicite &#8230;</p>
<p>Après recherche dans l&rsquo;edmx <img style="border-bottom-style: none; border-right-style: none; border-top-style: none; border-left-style: none" class="wlEmoticon wlEmoticon-smile" alt="Sourire" src="http://blog.developpez.com/media/333/wlEmoticon-smile.png" /> , partie mapping (msl, merci Mme Julie Lerman pour votre beau livre), je note un noeud dupliqué : (merci Mr Altova pour votre magnifique XmlSpy)</p>
<p><a href="http://blog.developpez.com/media/333/EF4-EDMX-DESIGNER-BUG-ANALYSE.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="EF4-EDMX-DESIGNER-BUG-ANALYSE" border="0" alt="EF4-EDMX-DESIGNER-BUG-ANALYSE" src="http://blog.developpez.com/media/333/EF4-EDMX-DESIGNER-BUG-ANALYSE_thumb.png" width="262" height="331" /></a></p>
<p>Je supprime les lignes doublonnées, et relance la mise à jour du modèle et BINGO ! ca marche !</p>
<p>Résultat des courses :</p>
<p>Le designer construit l&rsquo;edmx de façon incrémentielle, sans refactoriser les données par types (l&rsquo;ordre d&rsquo;apparition des noeuds enfant dans les parties CSDL, MSL et SSDL est fonction des mises à jour du modèle)</p>
<p>Le designer ne vérifie pas (toujours) si dans l&rsquo;EDMX une notion existe déjà, ce qui peut entrainer le bug que nous avons eu.</p>
<p>En cas d&rsquo;apparition du bug, la seule solution consiste à se palucher l&rsquo;edmx à la manno ! (dans notre cas 75 classes, et le reste qui va avec -> héritage, x tables pour une classe, etc &#8211; )</p>
<p>Bon à savoir !</p>
<p>PS : Hormis cela, EF4 est une belle bête, qui demeure fiable ! </p>
<p>Re PS : merci David pour ton aide dans l&rsquo;analyse de l&rsquo;edmx&#8230; nous n&rsquo;avions pas trop de 2 paires d&rsquo;yeux !<img style="border-bottom-style: none; border-right-style: none; border-top-style: none; border-left-style: none" class="wlEmoticon wlEmoticon-smile" alt="Sourire" src="http://blog.developpez.com/media/333/wlEmoticon-smile.png" /></p>
<p>@+</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WCF RIA Services et les Query &#171;&#160;maison&#160;&#187;, ou comment implémenter des query complexes</title>
		<link>https://blog.developpez.com/bdevuyst/p8703/dotnet-net/silverlight/wcf_ria_services_query_complexes</link>
		<comments>https://blog.developpez.com/bdevuyst/p8703/dotnet-net/silverlight/wcf_ria_services_query_complexes#comments</comments>
		<pubDate>Mon, 08 Mar 2010 15:05:53 +0000</pubDate>
		<dc:creator><![CDATA[benji_dv]]></dc:creator>
				<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WCF Ria Services]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Bonjour à vous ! Un petit post mignon tout plein aujourd&#8217;hui. WCF RIA Services nous permet de requêter, de façon quasi transparente, une source de données depuis une application cliente Silverlight (par exemple). La syntaxe utilisée consiste à appeler Load de l&#8217;objet DomainContext instancié et de lui préciser quelle query utiliser. Ce mécanisme suffit largement pour des filtrages basiques. Lorsque l&#8217;on a à utiliser des filtrage plus complexes, RIA se trouve vite à bout de [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Bonjour à vous ! Un petit post mignon tout plein aujourd&rsquo;hui. </p>
<p>WCF RIA Services nous permet de requêter, de façon quasi transparente, une source de données depuis une application cliente Silverlight (par exemple). </p>
<p>La syntaxe utilisée consiste à appeler Load de l&rsquo;objet DomainContext instancié et de lui préciser quelle query utiliser. </p>
<p>Ce mécanisme suffit largement pour des filtrages basiques. </p>
<p>Lorsque l&rsquo;on a à utiliser des filtrage plus complexes, RIA se trouve vite à bout de souffle.</p>
<p>Pour les exemples ci dessous, nous considérons que nous disposons du modèle de données suivant (Entity Framework par exemple) :<br />
Une voiture contient 0-n roues,<br />
Les roues ne sont pas retournées par défaut avec les voitures sur le client (via RIA).
</p>
<p>
Exemple de situation complexe : </p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> var monDomainCtx = <span style="color: #0000ff">new</span> VehiculeDomainSrv();</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> var query = monDomainCtx.GetVoitureQuery().Where(</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     voiture =&gt; voiture.Roues.Any(roue=&gt;roue.IsAPlat));</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> monDomainCtx.Load&lt;Voiture&gt;(</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>     query,</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>     loadOp=&gt;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>     {</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>         ... <span style="color: #008000">// opération de chargement des voitures à pneu plat</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>     },</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>     <span style="color: #0000ff">false</span>);</pre>
</p></div>
</div>
<p>Nous tentons ici (côté client), de demander à RIA d’aller rechercher toutes les voiture qui ont (au moins) un pneu crevé (sous requête).<br />
  <br />Dans ce cas de figure (présence d’une ou plusieurs sous requête), RIA va nous renvoyer une exception dont le message parlera d’une impossibilité d’utiliser Any (mais ce serait la même chose pour Count, First, etc).</p>
<p><b>La solution : </b></p>
<p>Dans le DomainServices (donc sur le serveur), nous allons implémenter une méthode décorée de l’attribut &laquo;&nbsp;System.Web.DomainServices.QueryAttribute&nbsp;&raquo;. Nous implémentons donc nos propres query !</p>
<p>Cette méthode retournera donc un objet IQueryable (au même titre que celles fournies par défaut : GetVoitureQuery() )</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> [Query()]</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> <span style="color: #0000ff">public</span> IQueryable&lt;Voiture&gt; GetFiltreVoitures(Boolean roueCrevee)</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> {</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     <span style="color: #008000">// création de la query de base retournéà partir du DataModel</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>     var dataCtx = <span style="color: #0000ff">new</span> GarageLocationDataModel();</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>     </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>     <span style="color: #0000ff">return</span> dataCtx.Voiture.Where(voit =&gt; voit.Roue.Any(roue =&gt; roue.IsAPlat));</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span> }</pre>
</p></div>
</div>
<p>Lors de l’exécution, nous utiliserons le code suivant (côté client)</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> var dataCtx = <span style="color: #0000ff">new</span> VehiculeDomainSrv();</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span>&#160; </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> dataCtx.Load&lt;Vehicule&gt;(</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     dataCtx.GetFiltreVoiture(true),</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>     loadOp=&gt;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>     {</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>         <span style="color: #008000">// Corps de méthode pour récupérer les résultats</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>         ...</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>     },</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>     <span style="color: #0000ff">false</span>);</pre>
</p></div>
</div>
<p>Le client ne fait que demander l&rsquo;exécution de la query, cette dernière sera bien entendu exécutée (physiquement) sur le serveur.</p>
<p>Petite précision sur les méthodes Query :</p>
<p>Il faut noter une petite restriction concernant les paramètres des query : il n’est pas possible (à ce jour) de passer en paramètre un objet d’un type qui encapsule tous les critères de recherche (exemple : CritereVehicule).</p>
<p>En effet, les seuls types autorisés par RIA comme paramètre de query sont les classes qui héritent d’EntityObject et les types simples.<br />
  <br />Nous sommes donc “forcés” de lier les couches fortement (pour le moment).</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entity framework 3.5, procédures stoquées, et &#171;&#160;Function imports&#160;&#187; qui retournent void</title>
		<link>https://blog.developpez.com/bdevuyst/p8677/dotnet-net/entity_framework_store_procedure_functio</link>
		<comments>https://blog.developpez.com/bdevuyst/p8677/dotnet-net/entity_framework_store_procedure_functio#comments</comments>
		<pubDate>Wed, 03 Mar 2010 08:54:27 +0000</pubDate>
		<dc:creator><![CDATA[benji_dv]]></dc:creator>
				<category><![CDATA[DotNet - .net]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[WCF Ria Services]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Entity Framework (dans sa version 3.5) permet d&#8217;exploiter des procédures stoquées afin de disposer de comportements particuliers. Exemple : nous désirons supprimer des objets en cascade (suppression d&#8217;une commande, qui implique la suppression des lignes de commandes, qui implique &#8230;). Cette suppression sera plus rapide si son exécution est confiée au moteur de base de données, plutôt que par des appels multiples sur un contexte EF. D&#8217;où la création d&#8217;une procédure stoquée, et son intégration [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Entity Framework (dans sa version 3.5) permet d&rsquo;exploiter des procédures stoquées afin de disposer de comportements particuliers. </p>
<p><em>Exemple</em> : nous désirons supprimer des objets en cascade (suppression d&rsquo;une commande, qui implique la suppression des lignes de commandes, qui implique &#8230;). </p>
<p>Cette suppression sera plus rapide si son exécution est confiée au moteur de base de données, plutôt que par des appels multiples sur un contexte EF. </p>
<p>D&rsquo;où la création d&rsquo;une procédure stoquée, et son intégration au sein d&rsquo;EF. </p>
<p>Lorsque l&rsquo;on désire exploiter les procédures stoquées au sein d&rsquo;EF, il suffit de passer par une &quot;Function Imports&quot; mappée sur la procédure référencée au préalable dans EF.<br />
  <br />Si cette dernière un objet déjà exploité par EF, aucun problème : la méthode liée à la procédure est dynamiquement générée dans le contexte EF lors de la création de la fonction EF.<br />
Par contre, lorsqu&rsquo;il s&rsquo;agit de retourner un type simple ou <code class="codecolorer text default"><span class="text">void</span></code> : la méthode n&rsquo;est pas générée&#8230;</p>
<p>Dans ce cas de figure, il faut donc &quot;mettre les mains dans le moteur&quot;.<br />
  <br />Pour ce faire, voici les étapes : </p>
<ol>
<li>Créez votre procédure stoquée (qui ne retourne rien&#8230;),<br />
    </li>
<li>Dans Visual Studio, ouvrez l&rsquo;edmx, et sur le schéma, cliquez droit (menu contextuel), sélectionnez &quot;Update Model From database&quot; (voir ci dessous)<br />
    <br /><img alt="EF-FunctionImport1" src="http://blog.developpez.com/media/EF-FunctionImport1.png" width="281" height="319" /> </p>
<p></li>
<li>Dans l&rsquo;écran de synchronisation du modèle Entity Framework, déployez Stored Procedure et sélectionnez celle à &quot;injecter&quot; comme fonction dans Entity Framework, et validez…<br />
    <br /><img alt="EF-FunctionImport2" src="http://blog.developpez.com/media/EF-FunctionImport2.png" width="395" height="404" /> </p>
<p></li>
<li>Ouvrez le Model Browser, et dans la partie qui concerne la description de la base de données utilisée par EF, déployez Store Procedure. Click droit sur celle qui nous intéresse et sélectionnez &quot;Create Function Import&quot;<br />
    <br /><img alt="EF-FunctionImport3" src="http://blog.developpez.com/media/EF-FunctionImport3.png" width="395" height="404" />&#160; <br />(ce qui est grisé est le nom du datamodel du projet) </p>
</li>
<li>Cela entraine l&rsquo;ouverture de l&rsquo;écran de paramétrage de la fonction.<br />
    Ecran dans lequel, nous pouvons ajouter des précisions concernant la fonction (donc son nom). </p>
<p><img alt="EF-FunctionImport4" src="http://blog.developpez.com/media/EF-FunctionImport4.png" width="417" height="306" />&#160; </p>
<p><b>Passé ce stade ci, si le type de retour avait été Entity (un objet géré par EF), il aurait généré le code permettant l&rsquo;appel de la fonction. </p>
<p>
</b>Pour vérifier qu&rsquo;il a bien enregistré la fonction : ouvrez le Model Browser, et déployer la partie entity jusqu&rsquo;aux fonctions : </p>
<p><img alt="EF-FunctionImport6" src="http://blog.developpez.com/media/EF-FunctionImport6.png" width="386" height="255" />&#160; </li>
<li>Créez une classe partielle portant le même nom, et même namespace que le contexte entity de votre modèle de données.
<p><strong>PS : Pour connaitre le nom de la classe : </strong></p>
<ul>
<li>ouvrez l&rsquo;edmx </li>
<li>cliquez sur l&rsquo;arrière plan </li>
<li>F4 pour ouvrir l&rsquo;écran de propriétés </li>
<li>reprenez le nom de la propriété &quot;Entity Container Name&quot;<br />
        <br /><img alt="EF-FunctionImport5" src="http://blog.developpez.com/media/EF-FunctionImport5.png" width="391" height="349" /> </p>
<p></li>
</ul>
<p>    <strong>Re-PS : Pour connaitre le chemin du namespace de la classe :<br />
      <br /></strong>Ouvrez le fichier .cs lié à l&rsquo;edmx, et copiez le namespace en tête de fichier. </p>
<p>Maintenant que vous disposez du nom complet de la classe (namespace + nom de classe), vous pouvez créer une classe qui va porter le même nom, même namespace, mais avec le mot clé partial. <code class="codecolorer text default"><span class="text">&amp;#160; &lt;br /&gt;</span></code></p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">namespace</span> MonNamespaceEF  </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {    </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     <span style="color: #0000ff">using</span> System;    </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     <span style="color: #0000ff">using</span> System.Collections.Generic;    </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>     <span style="color: #0000ff">using</span> System.Linq;    </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>     <span style="color: #0000ff">using</span> System.Text;      </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>&#160; </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> MainDataModel    </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>     {        </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>     }  </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span> }  </pre>
</div></div>
</li>
<li>Dernière étape : le code permettant d&rsquo;exploiter EF par &quot;l&rsquo;intérieur&quot;.
<p>Avant de montrer le code, une petite explication. </p>
<p>Entity Framework est une couche de type DAL (couche permettant les accès aux données + le mapping relationnel objet).<br />
    <br />Étant donné qu&rsquo;EF est conçu pour pouvoir fonctionner sur plusieurs sources de données (SQL Server, ou autre), il offre à l&rsquo;utilisateur ses propres implémentations de DbConnection, DbCommand, etc afin de garder cette indépendance.<br />
    Donc, dans le code exposé ci dessous, nous n&rsquo;utilisons ni d’OleDb, ni de SQLClient mais bien EntityConnection, EntityCommand, etc. </p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">namespace</span> ClassLibrary1</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     <span style="color: #0000ff">using</span> System;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     <span style="color: #0000ff">using</span> System.Collections.Generic;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>     <span style="color: #0000ff">using</span> System.Linq;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>     <span style="color: #0000ff">using</span> System.Text;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>     <span style="color: #0000ff">using</span> System.Data.EntityClient;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>&#160; </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> MainDataModel</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>     {</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>         <span style="color: #008000">/// &lt;summary&gt; </span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span>         <span style="color: #008000">/// Supprime une machine en profondeur (impacte toutes les tables liées) </span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span>         <span style="color: #008000">/// &lt;/summary&gt; </span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14">  14:</span>         <span style="color: #008000">/// &lt;param name=&quot;idGamme&quot;&gt;The id gamme.&lt;/param&gt; </span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15">  15:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> DeleteMachineDeep(String codeMachine)</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16">  16:</span>         {</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17">  17:</span>             <span style="color: #008000">// Crée une connection à partir de la cnnStr du datacontext </span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18">  18:</span>             <span style="color: #0000ff">using</span> (EntityConnection conn = <span style="color: #0000ff">new</span> EntityConnection(<span style="color: #0000ff">this</span>.Connection.ConnectionString))</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19">  19:</span>             {</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum20">  20:</span>                 <span style="color: #0000ff">try</span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum21">  21:</span>                 {</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum22">  22:</span>                     EntityCommand cmd = conn.CreateCommand(); <span style="color: #008000">// crée une EntityCommand </span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum23">  23:</span>&#160; </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum24">  24:</span>                     <span style="color: #008000">// CommandText correspond au nom de la fonction d'import (au sens Entity) </span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum25">  25:</span>                     <span style="color: #008000">// le format d'identification est 'ContainerName.Stored Proc Name'  </span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum26">  26:</span>                     cmd.CommandText = String.Format(<span style="color: #006080">&quot;{0}.{1}&quot;</span>, <span style="color: #0000ff">this</span>.DefaultContainerName, <span style="color: #006080">&quot;SUPPR_MACHINE&quot;</span>);</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum27">  27:</span>&#160; </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum28">  28:</span>                     cmd.CommandType = System.Data.CommandType.StoredProcedure;</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum29">  29:</span>                     cmd.Parameters.AddWithValue(<span style="color: #006080">&quot;codeMachine&quot;</span>, codeMachine); <span style="color: #008000">// ajout du param </span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum30">  30:</span>&#160; </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum31">  31:</span>                     conn.Open();</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum32">  32:</span>&#160; </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum33">  33:</span>                     cmd.ExecuteNonQuery();</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum34">  34:</span>                 }</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum35">  35:</span>                 <span style="color: #0000ff">catch</span> (Exception)</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum36">  36:</span>                 {</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum37">  37:</span>                     conn.Close();</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum38">  38:</span>                     <span style="color: #0000ff">throw</span>; <span style="color: #008000">// renvoi l'exception pour traitement, </span></pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum39">  39:</span>                 }</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum40">  40:</span>             }</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum41">  41:</span>         }</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum42">  42:</span>     }</pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum43">  43:</span> }</pre>
</div></div>
</li>
<li>L&rsquo;utilisation :
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> ...    </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> var dataCtx = <span style="color: #0000ff">new</span> MainDataModel();    </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> dataCtx.DeleteMachineDeep(<span style="color: #006080">&quot;ST1236&quot;</span>);  </pre>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>  ...  </pre>
</div></div>
</li>
</ol>
<p>Avant de conclure, je souhaite revenir sur un point important : le fait qu&rsquo;EF utilise des types d&rsquo;objets de manipulation de source de données indépendant des implémentations réelle (EntityCommand, EntityConnection, etc) prouve qu&rsquo;il a été conçu pour être exploité de façon indépendante du type de moteur de base de données sur lequel il s&rsquo;appuie (et ce proprement).<br />
  </p>
<p>@+ </p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
