Programming Entity Framework
Programming Entity Framework By Julia Lerman
February 2009
Pages: 828


Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Adding Native View To Model
Bob Bedell
post Nov 3 2009, 06:58 PM
Post #1


Active Member
**

Group: Members
Posts: 15
Joined: 3-November 09
Member No.: 20,856



Hello,

When I run the SQL on page 368 in the section 'Adding Native View to Model' in SqlServer, the correct records are returned. I'm using ContactID 199. Two payments: $800.00 and $1500.

I created the Function:

CODE
<Function Name="PaymentsforContact" IsComposable="false" >
          <CommandText>
            SELECT Payments.PaymentDate,
            Payments.Amount,
            Reservations.ReservationDate,
            Contact.FirstName,
            Contact.LastName,
            Events.StartDate,
            Events.EndDate,
            Locations.LocationName
            FROM   Payments INNER JOIN
            Reservations ON Payments.ReservationID = Reservations.ReservationID INNER JOIN
            Contact ON Reservations.ContactID = Contact.ContactID INNER JOIN
            Events ON Reservations.EventID = Events.EventID INNER JOIN
            Locations ON Events.LocationID = Locations.LocationID
            WHERE Contact.ContactID = @ContactID
          </CommandText>
          <Parameter Name="ContactID" Type="int" Mode="In" />
        </Function>


When I execute the following line ofo code:

CODE
var payments = context.PaymentsforContact(199).ToList();


the List contains 2 objects of type 'vPaymentsforPeriod' as expected. Oddly, they both contain the same data, the payment made on 4/6/2008 for $800. I was expecting the second object to contain data for the other payment made on 1/1/2008 for $1500.

Any thoughts??

Thanks,

Bob
Go to the top of the page
 
+Quote Post
JulieLerman
post Nov 3 2009, 10:58 PM
Post #2


Active Member
****

Group: O'Reilly Author
Posts: 102
Joined: 17-September 08
Member No.: 836



I guess the first thing I'm required to ask is: did you verify the TSQL directly? I.e. run the query in Visual studio or SQL Server Management Studio?
Go to the top of the page
 
+Quote Post
Bob Bedell
post Nov 4 2009, 02:25 AM
Post #3


Active Member
**

Group: Members
Posts: 15
Joined: 3-November 09
Member No.: 20,856



QUOTE (JulieLerman @ Nov 3 2009, 10:58 PM) *
....did you verify the TSQL directly?


Yup, mentioned that in the first clause of my post. Runs fine in SQL Server Management Studio. Returns two correct records. Its the identical SQL used in the book. Just returns two identical 'vPaymentsforPeriod' objects when run in code.

Running:

CODE
var payments = context.PaymentsforContact(199).ToList();

                    foreach (var payment in payments)
                    {
                        Console.WriteLine("{0} {1}", payment.PaymentDate.ToString(),
                                                     payment.Amount.ToString());
                    }


outputs:

4/6/2008 12:00:00 AM 800.0000
4/6/2008 12:00:00 AM 800.0000

I'd was hoping it would output:

4/6/2008 12:00:00 AM 800.0000
1/1/2008 12:00:00 AM 1500.0000

Kinda' odd. Thanks for the reply.

Bob
Go to the top of the page
 
+Quote Post
JulieLerman
post Nov 4 2009, 03:10 AM
Post #4


Active Member
****

Group: O'Reilly Author
Posts: 102
Joined: 17-September 08
Member No.: 836



Sorry, I am travelling and thought the function you created was different than the sql on page 368 since I don't have a copy of my book. therefore I am did not realize that it was the same SQL in both cases.

I am at a conference right now getting ready for some talks and won't be able to investigate right away. I'd want to go back to my original examples that I built which I can't do at the moment.

I have no idea why there would be a difference between what the function returns and the what SQL Server returns. Possibly a difference in relationships in the model or something.




Go to the top of the page
 
+Quote Post
Bob Bedell
post Nov 4 2009, 12:48 PM
Post #5


Active Member
**

Group: Members
Posts: 15
Joined: 3-November 09
Member No.: 20,856



[errant post, my bad]

This post has been edited by Bob Bedell: Nov 4 2009, 12:55 PM
Go to the top of the page
 
+Quote Post
Bob Bedell
post Nov 4 2009, 12:54 PM
Post #6


Active Member
**

Group: Members
Posts: 15
Joined: 3-November 09
Member No.: 20,856



No problem. Enjoy the conference if you can. Public speaking makes me want to chew on table legs.

I'm off to the next topic (glad to have your book by the way), and will revisit Native Queries again the next time they cross my path. There are much more interesting things in the EF to get confused about.

Best,

Bob
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 22nd November 2009 - 04:41 PM