<?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>Vince Plaza&#039;s Blog</title>
	<atom:link href="http://www.vinceplaza.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vinceplaza.com</link>
	<description>Microsoft .NET programming ideas and samples</description>
	<lastBuildDate>Tue, 20 Oct 2009 23:18:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sort on the last name in full name field using T-SQL string functions</title>
		<link>http://www.vinceplaza.com/2009/10/20/sort-on-the-last-name-in-full-name-field/</link>
		<comments>http://www.vinceplaza.com/2009/10/20/sort-on-the-last-name-in-full-name-field/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 23:11:38 +0000</pubDate>
		<dc:creator>Vince Plaza</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.vinceplaza.com/?p=220</guid>
		<description><![CDATA[A friend asked me if it was possible to sort on just a portion of a text field, but not necessarily the first word. For example, lets say you have a full name field that is formatted  as &#8216;[FirstName] [LastName]&#8216;. There is a simple, if not flawless, way to do this with T-SQL string functions. [...]]]></description>
			<content:encoded><![CDATA[<p>A friend asked me if it was possible to sort on just a portion of a text field, but not necessarily the first word. For example, lets say you have a full name field that is formatted  as &#8216;[FirstName] [LastName]&#8216;. There is a simple, if not flawless, way to do this with T-SQL string functions. First, you need to generate a small list of names to work with. I will use a table variable to do this. It is easy to spin up and is disposed of as soon as the query is done running.</p>
<p><code>declare @MyNames table (FullName nvarchar(20));<br />
insert @MyNames<br />
values ('Betty Ferguson'),('Sam L Jackson'),('Horatio Alger');</code></p>
<p>Note that I used the much simpler SQL Server 2008 syntax to add the names. If you are using SQL Server 2005, you will need to add the names like this:</p>
<p><code>insert @MyNames<br />
values ('Betty Ferguson');<br />
insert @MyNames<br />
values ('Sam L Jackson');<br />
insert @MyNames<br />
values ('Horatio Alger');</code></p>
<p>Since you can&#8217;t control people adding a middle initial, I will find the last name by counting the number of characters starting from the right before I find a space character. The best function to use for this is charindex.</p>
<p><code>select charindex(' ', FullName) as 'LastNameLetterCount' from @MyNames;</code></p>
<p>The problem is that the charindex function counts from the left. In order to count from the right, I need to flop the text over by using the reverse function. This function will take a string of characters such as &#8216;My dog spot&#8217; and return it as &#8216;tops god yM&#8217;. I also subtract 1 so that I only return the length of the last name, not the last name and the space.<br />
<span id="more-220"></span><br />
<code>select charindex(' ', reverse(FullName))-1 as 'LastNameLetterCount' from @MyNames;</code></p>
<p>This returns the following values:</p>
<p>LastNameLetterCount<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
8<br />
7<br />
5</p>
<p>Now I have the length of our last name. With this value, I can use the &#8216;right&#8217; function to isolate the last name value. This function will return the number of characters we indicate starting from the right. For instance right(&#8217;My String&#8217;,3) will return &#8216;ing&#8217;.</p>
<p><code>select right(FullName, charindex(' ', reverse(FullName))-1) as 'LastName' from @MyNames;</code></p>
<p>This will return the values:</p>
<p>LastName<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Ferguson<br />
Jackson<br />
Alger</p>
<p>However, I want to order by this field, not display it. To do that, I move the string functions to the &#8216;order by&#8217; clause and only display the original field.</p>
<p><code>select   FullName<br />
from     @MyNames<br />
order by right(FullName, charindex(' ', reverse(FullName))-1);</code></p>
<p>This will return the requested field in the desired ascending order:</p>
<p>FullName<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Horatio Alger<br />
Betty Ferguson<br />
Sam L Jackson</p>
<p>Of course to sort in reverse order, I could add the &#8216;desc&#8217; flag to the order by clause:</p>
<p><code>select   FullName<br />
from     @MyNames<br />
order by right(FullName, charindex(' ', reverse(FullName))-1) desc;</code></p>
<p>FullName<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Sam L Jackson<br />
Betty Ferguson<br />
Horatio Alger</p>
<p>You may have noticed the holes in this approach, such as the field only containing a first name, a two part last name, etc. However, for some quick querying on a known data set, this technique may get you pretty far.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinceplaza.com/2009/10/20/sort-on-the-last-name-in-full-name-field/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;Could not find default endpoint&#8221; error with Silverlight, WCF, and MVVM</title>
		<link>http://www.vinceplaza.com/2009/10/16/could-not-find-default-endpoint-error-with-silverlight-wcf-and-mvvm/</link>
		<comments>http://www.vinceplaza.com/2009/10/16/could-not-find-default-endpoint-error-with-silverlight-wcf-and-mvvm/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 22:10:23 +0000</pubDate>
		<dc:creator>Vince Plaza</dc:creator>
				<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Model-View-ViewModel (MVVM)]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://www.vinceplaza.com/?p=213</guid>
		<description><![CDATA[I have done this a couple of times, and so thought I would log it so that I remember next time. When I set up a Silverlight project using the MVVM pattern, I prefer to make separate projects for the View and ViewModel sections. I then create a service reference to my data service (WCF) [...]]]></description>
			<content:encoded><![CDATA[<p>I have done this a couple of times, and so thought I would log it so that I remember next time. When I set up a Silverlight project using the MVVM pattern, I prefer to make separate projects for the View and ViewModel sections. I then create a service reference to my data service (WCF) in the ViewModels project. If you have tried this, you may have received a &#8220;Cannot find &#8216;ServiceReferences.ClientConfig&#8217; in the .xap application package.&#8221; error message the first time you run the solution. This is caused by the Views project not containing the ServiceReferences.ClientConfig file created in the ViewModels project. No problem, just drag a copy from the ViewModels project into the Views project and you are set to go.</p>
<p>Where I get into trouble is when I reconfigure the WCF service or reference and forget to update the client config file I dragged into the Views project. The error message that gets generated is similar to:</p>
<blockquote><p>Could not find default endpoint element that references contract &#8216;ServiceReference.Service&#8217; in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.</p></blockquote>
<p>Well, I was much happier with the error message telling me the file was missing. With this new message, I end up opening the client config file in the ViewModels project like 6 times looking for a typo, but of course it was auto generated while making the service reference, and so is fine. What I need to do is to replace the ServiceReferences.ClientConfig file in the Views project, and then run the application again. Problem solved.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinceplaza.com/2009/10/16/could-not-find-default-endpoint-error-with-silverlight-wcf-and-mvvm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Great post on using Dependency Properties with custom user controls in Silverlight</title>
		<link>http://www.vinceplaza.com/2009/09/10/great-post-on-using-dependency-properties-with-custom-user-controls-in-silverlight/</link>
		<comments>http://www.vinceplaza.com/2009/09/10/great-post-on-using-dependency-properties-with-custom-user-controls-in-silverlight/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 06:20:32 +0000</pubDate>
		<dc:creator>Vince Plaza</dc:creator>
				<category><![CDATA[Model-View-ViewModel (MVVM)]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Binding]]></category>
		<category><![CDATA[DependencyProperty]]></category>

		<guid isPermaLink="false">http://www.vinceplaza.com/?p=191</guid>
		<description><![CDATA[I was stuck on implementing data binding with custom Silverlight controls, and found this post to be a lifesaver: http://geekswithblogs.net/PeterTweed/archive/2009/07/05/taking-advantage-of-data-binding-in-silverlight.aspx
]]></description>
			<content:encoded><![CDATA[<p>I was stuck on implementing data binding with custom Silverlight controls, and found this post to be a lifesaver: <a href="http://geekswithblogs.net/PeterTweed/archive/2009/07/05/taking-advantage-of-data-binding-in-silverlight.aspx#">http://geekswithblogs.net/PeterTweed/archive/2009/07/05/taking-advantage-of-data-binding-in-silverlight.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinceplaza.com/2009/09/10/great-post-on-using-dependency-properties-with-custom-user-controls-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Good reference on SSIS tuning techniques</title>
		<link>http://www.vinceplaza.com/2009/09/02/good-reference-on-ssis-tuning-techniques/</link>
		<comments>http://www.vinceplaza.com/2009/09/02/good-reference-on-ssis-tuning-techniques/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 19:34:42 +0000</pubDate>
		<dc:creator>Vince Plaza</dc:creator>
				<category><![CDATA[Integration Services (SSIS)]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://www.vinceplaza.com/2009/09/02/good-reference-on-ssis-tuning-techniques/</guid>
		<description><![CDATA[I am troubleshooting a memory allocation issue with an SSIS package and came across the following article. It is a couple of years old, but still very relevant:
Integration Services: Performance Tuning Techniques
]]></description>
			<content:encoded><![CDATA[<p>I am troubleshooting a memory allocation issue with an SSIS package and came across the following article. It is a couple of years old, but still very relevant:<br />
<a href="http://msdn.microsoft.com/en-us/library/cc966529.aspx">Integration Services: Performance Tuning Techniques</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinceplaza.com/2009/09/02/good-reference-on-ssis-tuning-techniques/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Missing SQL Server 2008 templates in Visual Studio Team System 2008 Database Edition</title>
		<link>http://www.vinceplaza.com/2009/09/01/missing-sql-server-2008-templates-in-visual-studio-team-system-2008-database-edition/</link>
		<comments>http://www.vinceplaza.com/2009/09/01/missing-sql-server-2008-templates-in-visual-studio-team-system-2008-database-edition/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 22:59:58 +0000</pubDate>
		<dc:creator>Vince Plaza</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[VSTS Database Edition]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.vinceplaza.com/2009/09/01/missing-sql-server-2008-templates-in-visual-studio-team-system-2008-database-edition/</guid>
		<description><![CDATA[I have a new install of Visual Studio Team System 2008 Database Edition that is updated to SP1. I went to make a new SQL Server 2008 project and noticed that there was not a template available. I thought this was odd as I have SQL Server 2008 installed locally. After a little research, I [...]]]></description>
			<content:encoded><![CDATA[<p>I have a new install of Visual Studio Team System 2008 Database Edition that is updated to SP1. I went to make a new SQL Server 2008 project and noticed that there was not a template available. I thought this was odd as I have SQL Server 2008 installed locally. After a little research, I was pointed to the following update: <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&#038;DisplayLang=en">Microsoft® Visual Studio Team System 2008 Database Edition GDR R2</a>.  After closing VSTS and installing the update file, I restarted VSTS and the templates were there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinceplaza.com/2009/09/01/missing-sql-server-2008-templates-in-visual-studio-team-system-2008-database-edition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use a view to encapsulate business logic and reduce code</title>
		<link>http://www.vinceplaza.com/2009/08/28/use-a-view-to-encapsulate-business-logic-and-reduce-code/</link>
		<comments>http://www.vinceplaza.com/2009/08/28/use-a-view-to-encapsulate-business-logic-and-reduce-code/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 03:36:02 +0000</pubDate>
		<dc:creator>Vince Plaza</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.vinceplaza.com/?p=153</guid>
		<description><![CDATA[This post adds to a previous post:Working with additive values in tables with different levels of detail
In the last post, we used a subquery to only show the latest value in a table that has a time component. The table holds an employee&#8217;s pay rate history and includes a &#8220;RateChangeDate&#8221; field. Although our use of [...]]]></description>
			<content:encoded><![CDATA[<p>This post adds to a previous post:<a href="http://www.vinceplaza.com/2009/08/25/working-with-additive-values-in-tables-with-different-levels-of-detail/">Working with additive values in tables with different levels of detail</a></p>
<p>In the last post, we used a subquery to only show the latest value in a table that has a time component. The table holds an employee&#8217;s pay rate history and includes a &#8220;RateChangeDate&#8221; field. Although our use of a subquery makes sense, over time it will become tedious to type the same code every time we want to show an employee&#8217;s current pay rate. In addition, the use of the subquery adds risk to the quality of our application. The business logic represented by the subquery will need to be tested every place the subquery appears, increasing the odds for an error down the road.</p>
<p>Since we know the subquery is a handy block of code, we will take advantage of a common database feature called a &#8220;view&#8221;. In a nutshell, a view is a persistent select query that is given a name and can be referenced just like a table. With a view, business logic can be defined once and shared between future queries and even between programmers.</p>
<p>Taking our last example, lets turn the subquery for the latest pay rate and turn it into a view. Note how we use the &#8220;create&#8221; statement just like when making a table.<br />
<code>create view HumanResources.CurrentEmployeePayrateView<br />
as<br />
select    e.EmployeeId<br />
          ,eph.Rate as Payrate<br />
from      (<br />
               select   EmployeeId<br />
                        ,max(RateChangeDate) as RateChangeDate<br />
               from     HumanResources.EmployeePayHistory<br />
               group by EmployeeId<br />
           ) e<br />
inner join HumanResources.EmployeePayHistory eph on e.EmployeeId = eph.EmployeeId<br />
                                    and e.RateChangeDate = eph.RateChangeDate<br />
</code><br />
<span id="more-153"></span><br />
Now we can replace the subquery in our query from the last post with a reference to our view like this:<br />
<code>select       e.EmployeeId<br />
             ,c.LastName + ', ' + c.FirstName as EmployeeName<br />
             ,e.VacationHours + e.SickLeaveHours - 120 as AccruedPtoHoursInExcess<br />
             ,cast((e.VacationHours + e.SickLeaveHours - 120) * f.Rate as decimal(6,2)) as Liability<br />
from         HumanResources.Employee e<br />
inner join   Person.Contact c on e.ContactId = c.ContactId<br />
inner join   HumanResources.CurrentEmployeePayRateView f on e.EmployeeId = f.EmployeeId                            <br />
where        VacationHours + SickLeaveHours &gt; 120;</code></p>
<p>A couple of notes: The view acts like a table in more ways than one. You can set permissions on it for specific user by using the &#8220;grant select&#8221; statement just like on a table. It is also possible to put an index on a view, but I do not recommend this for beginners as an index on a view can become complicated to manage. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinceplaza.com/2009/08/28/use-a-view-to-encapsulate-business-logic-and-reduce-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with additive values in tables with different levels of detail</title>
		<link>http://www.vinceplaza.com/2009/08/25/working-with-additive-values-in-tables-with-different-levels-of-detail/</link>
		<comments>http://www.vinceplaza.com/2009/08/25/working-with-additive-values-in-tables-with-different-levels-of-detail/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 17:44:14 +0000</pubDate>
		<dc:creator>Vince Plaza</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.vinceplaza.com/?p=126</guid>
		<description><![CDATA[Downloads: Sample Database
There are times when you need to perform a calculation on values stored in two different tables. The first value is stored in a summary level table, and the second is stored in a detail table. I will use the Adventure Works employee tables to demonstrate.
Let&#8217;s say you need to calculate the accrued [...]]]></description>
			<content:encoded><![CDATA[<p>Downloads: <a href="http://msftdbprodsamples.codeplex.com/">Sample Database</a></p>
<p>There are times when you need to perform a calculation on values stored in two different tables. The first value is stored in a summary level table, and the second is stored in a detail table. I will use the Adventure Works employee tables to demonstrate.</p>
<p>Let&#8217;s say you need to calculate the accrued vacation time for your employees that exceeds the company limit of 120 hours and derive the total liability to the company in terms of dollars. Using the Adventure Works database, that would require three tables: HumanResources.Employee, Person.Contact, and HumanResources.EmployeePayHistory. To start, we know we need to identify the employee so we include the EmployeeId field from the Employee table and the LastName and FirstName fields from the Contact table. Make sure and include the schema when declaring the tables, as this is required for any schema that is not &#8216;dbo&#8217;. This is a good practice anyway. Also, note the use of the table aliases &#8216;e&#8217; and &#8216;c&#8217; to save typing and add clarity.</p>
<p><code>select      e.EmployeeId<br />
            ,c.LastName + ', ' + c.FirstName as EmployeeName<br />
from        HumanResources.Employee e<br />
inner join  Person.Contact c on e.ContactId = c.ContactId</code><br />
<span id="more-126"></span><br />
Now we can easily calculate the accrued hours by adding two fields from the employees table: VacationHours and SickLeaveHours. We are assuming the business definition for the field is &#8216;hours accrued&#8217;, but this would need to be confirmed with the business owner. Since the column does not allow nulls, we do not need to trap for that using the ISNULL or COALESCE function. However, don&#8217;t forget to subtract the acceptable limit of 120 so we only see the delta.</p>
<p><code>select      e.EmployeeId<br />
            ,c.LastName + ', ' + c.FirstName as EmployeeName<br />
            ,e.VacationHours + e.SickLeaveHours - 120 as AccruedPtoHoursInExcess<br />
from        HumanResources.Employee e<br />
inner join  Person.Contact c on e.ContactId = c.ContactId</code></p>
<p>Since this will result in negative numbers for employees that have not accrued at least 120 hours, we might decide to trap that using the CASE statement and only return either a zero or a positive number. For our purposes, though, it makes sense to just show employees with a positive number. We will add a WHERE clause to limit our list. As a good practice, you should limit your results earlier in your development process or risk overburdening your database with an oversize result set. If you do not what your WHERE clause will be, you can still add a TOP declaration to your SELECT statement and limit the results to a manageable number of rows.  It is also a good idea to end your T-SQL statements with a semicolon, so I added one to our query.</p>
<p><code>select      e.EmployeeId<br />
            ,c.LastName + ', ' + c.FirstName as EmployeeName<br />
            ,e.VacationHours + e.SickLeaveHours - 120 as AccruedPtoHoursInExcess<br />
from        HumanResources.Employee e<br />
inner join  Person.Contact c on e.ContactId = c.ContactId<br />
where       e.VacationHours + e.SickLeaveHours &gt; 120;</code></p>
<p>Now for the tricky part. The pay rate for the employees is stored in the EmployeePayHistory table, but the table has a time component. In other words, there is a record added every time the pay rate changes. If we just add the table like follows, then we risk returning more than one record for a single employee. Note the new formula to caculate liability. I use parenthesis to enforce the correct order of operations:</p>
<p><code>select      e.EmployeeId<br />
            ,c.LastName + ', ' + c.FirstName as EmployeeName<br />
            ,VacationHours + SickLeaveHours - 120 as AccruedPtoHoursInExcess<br />
            ,cast((VacationHours + SickLeaveHours - 120) * eph.Rate as decimal(6,2)) as Liability<br />
from        HumanResources.Employee e<br />
inner join  Person.Contact c on e.ContactId = c.ContactId<br />
inner join  HumanResources.EMployeePayHistory eph on e.EmployeeId = eph.EmployeeId<br />
where       VacationHours + SickLeaveHours &gt; 120;</code></p>
<p>In my database, the latest query increases the row count from 97 to 99 because Rob Walters ends up with three records. We could just assume that Rob&#8217;s pay rate always increases, but that is prone to error. Instead, we need to add a subquery to only filter on the latest pay rates for each employee as determined by the RateChangeDate. The following query provides the filter we need:</p>
<p><code>select   EmployeeId<br />
         ,max(RateChangeDate) as RateChangeDate<br />
from     HumanResources.EmployeePayHistory<br />
group by EmployeeId</code></p>
<p>Now, all we need to do is add this into our main query so that it acts like a filter table, and join the original  EmployeePayHistory table to the derived filter table instead:</p>
<p><code>select      e.EmployeeId<br />
            ,c.LastName + ', ' + c.FirstName as EmployeeName<br />
            ,VacationHours + SickLeaveHours - 120 as AccruedPtoHoursInExcess<br />
            ,cast((VacationHours + SickLeaveHours - 120) * eph.Rate as decimal(6,2)) as Liability<br />
from        HumanResources.Employee e<br />
inner join  Person.Contact c on e.ContactId = c.ContactId<br />
inner join  (<br />
                select   EmployeeId<br />
                         ,max(RateChangeDate) as RateChangeDate<br />
                from     HumanResources.EmployeePayHistory<br />
                group by EmployeeId<br />
            ) f on e.EmployeeId = f.EmployeeId<br />
inner join  HumanResources.EmployeePayHistory eph on f.EmployeeId = eph.EmployeeId<br />
                                                    and f.RateChangeDate = eph.RateChangeDate<br />
where       VacationHours + SickLeaveHours &gt; 120;</code></p>
<p>The query now returns our original 97 rows and shows the current liability which is defined as &#8216;the current pay rate times the accrued PTO over 120 hours&#8217;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinceplaza.com/2009/08/25/working-with-additive-values-in-tables-with-different-levels-of-detail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update EF Model Properties to Match Conceptual Model</title>
		<link>http://www.vinceplaza.com/2009/08/13/update-ef-model-properties-to-match-conceptual-model/</link>
		<comments>http://www.vinceplaza.com/2009/08/13/update-ef-model-properties-to-match-conceptual-model/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 23:21:34 +0000</pubDate>
		<dc:creator>Vince Plaza</dc:creator>
				<category><![CDATA[Entity Framework (EF)]]></category>

		<guid isPermaLink="false">http://www.vinceplaza.com/?p=75</guid>
		<description><![CDATA[Before reading this post, read the previous post: Create an Adventure Works Entity Framework Model
Now that you have created an Entity Framework model for the Adventure Works database, you can begin to update properties to align the model with your business. In this example, I will change a few simple table properties to support future [...]]]></description>
			<content:encoded><![CDATA[<p>Before reading this post, read the previous post: <a href="http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/">Create an Adventure Works Entity Framework Model</a></p>
<p>Now that you have created an Entity Framework model for the Adventure Works database, you can begin to update properties to align the model with your business. In this example, I will change a few simple table properties to support future samples that use the model.</p>
<p>To start, open the AdventureWorks.edmx file in the Visual Studio GUI design tool. Select the SalesOrderDetail table by clicking on the table just below the table name in the header. The properties pane should look like this:</p>
<div id="attachment_79" class="wp-caption alignnone" style="width: 310px"><a rel="attachment wp-att-79" href="http://www.vinceplaza.com/2009/08/13/update-ef-model-properties-to-match-conceptual-model/ef_selecteftableandpropertiespane/"><img class="size-medium wp-image-79" title="Select EF Table and Properties Pane" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_SelectEfTableAndPropertiesPane1-300x216.jpg" alt="(click to enlarge)" width="300" height="216" /></a><p class="wp-caption-text">(click to enlarge)</p></div><br />
<span id="more-75"></span><br />
The change we are going to make is simple. Change the text in the Entity Set Name field to SalesOrderDetails. Doing this will allow us to differentiate between a single SalesOrderDetail and a set of details in our code and in Intellisense. Do the same thing for SalesOrderHeader, changing the plural value to SalesOrderHeaders. Change the Entity Set Name of the SalesPerson table to SalesPeople.</p>
<p>If you name your database tables with plural names like I do, you will notice one annoying feature of Entity Framework. If you change the Name value, lets say, from SalesPeople to SalesPerson, the designer will automatically change the Entity Set Name to SalesPersonSet. You will need to set it back to your plural value each time.</p>
<p>We will now change the name of the relationships to match our intention. The relationships are found at the bottom of the table under navigation properties. Starting with the SalesPerson table, right click the SalesOrderHeader relationship and select Rename in the context menu. Rename the relationship to SalesOrderHeaders by adding an &#8220;s&#8221;. In the SalesOrderHeader table, rename the relationshiop SalesOrderDetail to SalesOrderDetails. This is actually the beauty and intent of using the Entity Framework. I recommend seeing what happens when you change column name, table name and other properties as well, but this is all we need to do to support the upcoming samples.</p>
<p><div id="attachment_81" class="wp-caption alignnone" style="width: 310px"><a rel="attachment wp-att-81" href="http://www.vinceplaza.com/2009/08/13/update-ef-model-properties-to-match-conceptual-model/ef_adventurworksdatamodelwithnewentitysetnameprops1/"><img class="size-medium wp-image-81" title="AW Datamodel with new Entity Set Name Properties" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_AdventurworksDatamodelWithNewEntitySetNameProps11-300x194.jpg" alt="(click to enlarge)" width="300" height="194" /></a><p class="wp-caption-text">(click to enlarge)</p></div>
<p>The following code snippet shows how you will reference the newly named properties in code:</p>
<p><code>using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using Models;<br />
namespace ViewModels<br />
{<br />
    public class SalesOrderViewModel: ViewModelBase<br />
    {<br />
        private AdventureWorksEntities context;<br />
        private SalesOrderHeader currentSalesOrder;<br />
        public SalesOrderViewModel()<br />
       {<br />
            context = new AdventureWorksEntities();<br />
        }<br />
        private void SetCurrentSalesOrder(int SalesOrderId)<br />
        {<br />
            currentSalesOrder = context.SalesOrderHeaders.Where(so =&gt; so.SalesOrderId == SalesOrderId).FirstOrDefault();<br />
        }<br />
    }<br />
}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinceplaza.com/2009/08/13/update-ef-model-properties-to-match-conceptual-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create an Adventure Works Entity Framework Model</title>
		<link>http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/</link>
		<comments>http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 22:46:46 +0000</pubDate>
		<dc:creator>Vince Plaza</dc:creator>
				<category><![CDATA[Entity Framework (EF)]]></category>

		<guid isPermaLink="false">http://www.vinceplaza.com/?p=18</guid>
		<description><![CDATA[It is easy to create a simple Entity Framework model using the Adventure Works SQL Server database. I will use a WPF Model View project as my container. To start, create a new WPF Model View Application as described in this posting:
Right click on the Model folder in the Solution Explorer, select Add and then [...]]]></description>
			<content:encoded><![CDATA[<p>It is easy to create a simple Entity Framework model using the Adventure Works SQL Server database. I will use a WPF Model View project as my container. To start, create a new WPF Model View Application as described in this posting:</p>
<p>Right click on the Model folder in the Solution Explorer, select Add and then select New Item from the context menu.</p>
<div id="attachment_49" class="wp-caption alignnone" style="width: 310px"><a rel="attachment wp-att-49" href="http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/ef_addnewitemcontextmenu/"><img class="size-medium wp-image-49" title="Add New Item Context Menu" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_AddNewItemContextMenu-300x251.jpg" alt="(click to enlarge)" width="300" height="251" /></a><p class="wp-caption-text">(click to enlarge)</p></div>
<p>Select the ADO.Net Entity Data Model template and name it AdventureWorks.edmx.</p>
<div id="attachment_54" class="wp-caption alignnone" style="width: 310px"><a rel="attachment wp-att-54" href="http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/ef_newadventureworksedmxdialog/"><img class="size-medium wp-image-54" title="Choose the ADO.NET Entity Model Template" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_NewAdventureWorksEdmxDialog-300x164.jpg" alt="(click to enlarge)" width="300" height="164" /></a><p class="wp-caption-text">(click to enlarge)</p></div>
<p><span id="more-18"></span><br />
On the next dialog, create a connection to the AdventureWorksdatabase you plan on using, or select sn existing one using the drop down. Use the default recommendation for naming and storing the connection string in the App.config file. In my case, the connection name is prefixed with Milo because that is the name of my local machine.</p>
<div id="attachment_57" class="wp-caption alignnone" style="width: 310px"><a rel="attachment wp-att-57" href="http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/ef_chooseyourdataconnectiondialogforaw/"><img class="size-medium wp-image-57" title="Create or Select your AW Data Connection" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_ChooseYourDataConnectionDialogForAW-300x266.jpg" alt="(click to enlarge)" width="300" height="266" /></a><p class="wp-caption-text">(click to enlarge)</p></div>
<p>On the next dialog, select the option to create a model from a database.</p>
<div id="attachment_58" class="wp-caption alignnone" style="width: 310px"><a rel="attachment wp-att-58" href="http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/ef_generatefromdatabasedialog/"><img class="size-medium wp-image-58" title="Generate the AW Model from a Database" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_GenerateFromDatabaseDialog-300x266.jpg" alt="(click to enlarge)" width="300" height="266" /></a><p class="wp-caption-text">(click to enlarge)</p></div>
<p>Then select the tables you want to include. I selected three tables from the Sales schema for this example.</p>
<p><a rel="attachment wp-att-59" href="http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/ef_choosedatabaseobjextsdialog_awsalestables/"><img class="alignnone size-medium wp-image-59" title="EF_ChooseDatabaseObjextsDialog_AWSalesTables" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_ChooseDatabaseObjextsDialog_AWSalesTables-300x266.jpg" alt="EF_ChooseDatabaseObjextsDialog_AWSalesTables" width="300" height="266" /></a></p>
<p>That is all there is to it. The model should open up in the GUI designer.</p>
<div id="attachment_68" class="wp-caption alignnone" style="width: 310px"><a href="http://www.vinceplaza.com/?attachment_id=68"><img class="size-medium wp-image-68" title="Finished Adventure Works EF Model With Sales Tables" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_FinishedAdventureWorksEFModelWithSalesTablesSmall-300x244.jpg" alt="(click to enlarge)" width="300" height="244" /></a><p class="wp-caption-text">(click to enlarge)</p></div>
<p>In the next post I will show a couple of property changes I make to support future samples that use the model.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resetting metadata references in Entity Framework connection strings</title>
		<link>http://www.vinceplaza.com/2009/08/09/resetting-metadata-references-in-entity-framework-connection-strings/</link>
		<comments>http://www.vinceplaza.com/2009/08/09/resetting-metadata-references-in-entity-framework-connection-strings/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 01:49:24 +0000</pubDate>
		<dc:creator>Vince Plaza</dc:creator>
				<category><![CDATA[Entity Framework (EF)]]></category>

		<guid isPermaLink="false">http://www.plazaconsulting.net/blogs/vinceplaza/?p=3</guid>
		<description><![CDATA[I needed to move a couple of Entity Framework edmx files into a new project directory. Although I used the &#8220;add existing item&#8221; functionality of VS 2008, I still managed to corrupt the connection string entries in the App.config file, likely by using a subfolder. This led to a string of the following error message when [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to move a couple of Entity Framework edmx files into a new project directory. Although I used the &#8220;add existing item&#8221; functionality of VS 2008, I still managed to corrupt the connection string entries in the App.config file, likely by using a subfolder. This led to a string of the following error message when I tried to run the app: &#8220;Unable to load the specified metadata resource.&#8221; After searching for a fix, I found that by toggling a property of the edmx file, it is possible to realign the connection to the new project.</p>
<p>To do this, open the model in the Visual Studio GUI tool for editing edmx files. Use your cursor to select any point in the background of the diagram where there is not an object. If you look at your properties pane, you will notice a property for the diagram called &#8220;Metadata Artifact Processing&#8221;.</p>
<div id="attachment_8" class="wp-caption alignleft" style="width: 290px"><a rel="attachment wp-att-8" href="http://www.vinceplaza.com/2009/08/09/resetting-metadata-references-in-entity-framework-connection-strings/ef_metadataartifactprocessing/"><img class="size-medium wp-image-8" title="EF_MetadataArtifactProcessing" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_MetadataArtifactProcessing-280x300.jpg" alt="Screenshot of VS2008 designer and properties pane" width="280" height="300" /></a><p class="wp-caption-text">Screenshot of VS2008 designer and properties pane</p></div>
<div class="mceTemp mceIEcenter"> </div>
<p>The default value for this property is &#8220;Embed in Output Assembly&#8221; and this appears to be accepted as the best default practice. To repair your metadata reference, though, change the value to &#8220;Copy to Output Directory&#8221; and build the project. Now set the value back to the original &#8220;Embed in Output Assembly&#8221;.  Build the project again and you should be set to go. As this updates the App.config file, don&#8217;t forget to copy the updated entries to other projects that rely on the setting at run time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinceplaza.com/2009/08/09/resetting-metadata-references-in-entity-framework-connection-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
