Main Page | Report this Page
.NET DotNet Forum Index  »  ADO .NET Forum  »  Which Data Access Model to use with ASP.Net MVC...
Page 1 of 1    

Which Data Access Model to use with ASP.Net MVC...

Author Message
RichB...
Posted: Tue Sep 08, 2009 11:01 am
Guest
I'm not sure if this is the right place to post this, but I would be grateful
for some advice on selecting a data access model for my MVC application.

I have tried using Linq to SQL and Entity Framework, both with mixed results.

Linq to SQL I probably can make work, though the adjustments I would need to
cater for EntitySets
(http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.dotnet.framework.aspnet&tid=16206efb-35ba-47e2-ba87-3f8559e85f60&cat=en_US_7e59df4a-dfb8-42f1-b889-19bb40bca7c0&lang=en&cr=US&sloc=en-us&m=1&p=1)
made me start looking at the Entity Framework. I cannot however get this to
work for creation of objects in the following scenario:

I have an activity which may occur at one or more locations on different
dates. I want to find all future activities (comprised of multiple objects)
and order them by the distance from my current location. I found this
article: http://blog.wekeroad.com/2007/08/30/linq-and-geocoding/ which I know
is referring to Linq to Sql, but I assume it also applies equally to Linq to
Entities. It basically concludes that Linq is unable to generate the SQL
required, and that a two stage process is required to get the data, then
filter by distance. I feel that the number of objects created relative to the
filtered number is too large to take this approach.

I’m also not sure that Linq to SQL is the best long term option as MS moves
effort away to EF.

I also understand that EF SP support is due to be improved in .NET 4.
However in the meantime what are my options?

Should I use Linq to SQL for this SP and EF for other actions.

OR is there another approach to SP with EF in my distance from scenario
which will allow me to create the objects for my List of Activities?
 
Miha Markic...
Posted: Wed Sep 09, 2009 6:50 am
Guest
Yep, just use the data access technology that suits you best.
The choice is unrelated to asp.net mvc...
And besides Linq to SQL and EF there are plenty of other ORMs out there.
I'd recommend checking out LLBLGenPro.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: blog.rthand.com


"RichB" <richsanswers at (no spam) community.nospam> wrote in message
news:B9A45E87-DDB8-468A-8875-3648972BF370 at (no spam) microsoft.com...
Quote:
I'm not sure if this is the right place to post this, but I would be
grateful
for some advice on selecting a data access model for my MVC application.
 
RichB...
Posted: Wed Sep 09, 2009 8:53 am
Guest
Thanks, what you say makes sense. I realise that there is not a huge amount
to go on in the information which I provided.

My concern with leaving the business layer to filter and order based on
distance could cause performance issues.

Say I have a paginated view or 20 Activities, but the request is for
activities occurring within the next 2 weeks. My total database response
could be say 60000 activities occurring nationally within the next week. So
in order to present the first 20 activities then I have to retrieve the 60000
activities and then sort them in the business layer. That sounds like a lot
of data to move around when I could instead ask the database to return just
the first 20.

Is there a point at which you would suggest a different approach, or is
processing the data on the business layer not going to have a significant
effect on performance? If there is a significant effect, then what other
options are available using ORM?
 
RichB...
Posted: Wed Sep 09, 2009 8:57 am
Guest
Thanks I'll take a look at LLBLGenPro. Alot of my issues are with getting to
grips with the technologies, and the MVC model binding doesn't seem to play
ball with EntitySets created by Linq to SQl.

I guess I need to get the technology which does suit me and then work out
the custom model binding in MVC.

Thanks for your response.
Richard
 
Miha Markic...
Posted: Thu Sep 10, 2009 2:02 am
Guest
"RichB" <richsanswers at (no spam) community.nospam> wrote in message
news:8FA7A043-BB39-4BA9-BBD4-EB03F6AB5D12 at (no spam) microsoft.com...
Quote:
Thanks I'll take a look at LLBLGenPro. Alot of my issues are with getting
to
grips with the technologies, and the MVC model binding doesn't seem to
play
ball with EntitySets created by Linq to SQl.

Not sure exactly what your problem is but try using .ToList() method on
retrieved data before binding.

Quote:

I guess I need to get the technology which does suit me and then work out
the custom model binding in MVC.

The first makes sense anyway while the later might not be required.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: blog.rthand.com
 
Miha Markic...
Posted: Thu Sep 10, 2009 2:04 am
Guest
If you really don't have any special need then I'd fetch only the records
required (20 in your example) - which is (or should be) pretty
straightforward with any ORM.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: blog.rthand.com

"RichB" <richsanswers at (no spam) community.nospam> wrote in message
news:DEE96AF8-C709-4355-BAC9-DB83A765E28E at (no spam) microsoft.com...
Quote:
Thanks, what you say makes sense. I realise that there is not a huge
amount
to go on in the information which I provided.

My concern with leaving the business layer to filter and order based on
distance could cause performance issues.

Say I have a paginated view or 20 Activities, but the request is for
activities occurring within the next 2 weeks. My total database response
could be say 60000 activities occurring nationally within the next week.
So
in order to present the first 20 activities then I have to retrieve the
60000
activities and then sort them in the business layer. That sounds like a
lot
of data to move around when I could instead ask the database to return
just
the first 20.

Is there a point at which you would suggest a different approach, or is
processing the data on the business layer not going to have a significant
effect on performance? If there is a significant effect, then what other
options are available using ORM?




 
RichB...
Posted: Thu Sep 10, 2009 2:34 am
Guest
Yes, that is my problem though what options do I have (In EF):

1. A Linq query is too "complicated" for the sql generation.
2. A Stored Procedure can only be mapped to a single entity.

Or is there an appropriate way to get around either of these issues I have
encountered?
 
RichB...
Posted: Fri Sep 11, 2009 8:44 am
Guest
Ok, how about this approach:

from occ in context.Occurrences
join i in db.NearestEvents().Skip(startingRecord).Take(20)
on occ.Id equals i.Id
select occ;

It seems to work, but what is it actually doing under the hood?
NearestEvents() is a table valued function returning the IDs of the
occurrence records that it finds (I've not actually incorporated the logic
for distance at present). Would this all get run on the DB? (As far as I can
tell in SQL Server Profiler it is running the following-
SELECT [t0].[Id].....FROM [dbo].[Occurrence] AS [t0]INNER JOIN ( SELECT
TOP (1) [t1].[Id] FROM [dbo].[NearestEvents]() AS [t1] ) AS [t2] ON
[t0].[Id] = [t2].[Id]

). I haven't tried with EF as I think that I'm going to stick down the Linq
to Sql route, but am I correct in assuming that it would work there too?

Finally in Linq to Sql, is it usual to create several linq-to-Sql models
dependent on the data required for each call?

Thanks, Richard
 
Paul...
Posted: Wed Sep 23, 2009 7:01 am
Guest
There is no replacement for creating your own DAL / Model .
 
Miha Markic...
Posted: Sun Sep 27, 2009 1:49 pm
Guest
"RichB" <richsanswers at (no spam) community.nospam> wrote in message
news:01C4A2C4-F0B2-4951-8B56-DF5F7DDED39B at (no spam) microsoft.com...
Quote:

Ok, how about this approach:

from occ in context.Occurrences
join i in db.NearestEvents().Skip(startingRecord).Take(20)
on occ.Id equals i.Id
select occ;

It seems to work, but what is it actually doing under the hood?

Profiler or some other logging facitily will tell you if you are interested
(and it is a good thing to look under the hood).

Quote:
NearestEvents() is a table valued function returning the IDs of the
occurrence records that it finds (I've not actually incorporated the logic
for distance at present). Would this all get run on the DB? (As far as I
can
tell in SQL Server Profiler it is running the following-
SELECT [t0].[Id].....FROM [dbo].[Occurrence] AS [t0]INNER JOIN ( SELECT
TOP (1) [t1].[Id] FROM [dbo].[NearestEvents]() AS [t1] ) AS [t2] ON
[t0].[Id] = [t2].[Id]

). I haven't tried with EF as I think that I'm going to stick down the
Linq
to Sql route, but am I correct in assuming that it would work there too?

There is no guarantee since every ORM might implement LINQ queries
differently or not at all. But I'd assume it would work.

Quote:

Finally in Linq to Sql, is it usual to create several linq-to-Sql models
dependent on the data required for each call?

What do you mean by models?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: blog.rthand.com
 
RichB...
Posted: Fri Oct 02, 2009 9:15 am
Guest
Sorry I hadn't noticed your reply. By Models I probably mean contexts. So
for example I have a venues context for accessing data to do with venues, and
an activities context for accessing data associated to activities. I may also
have a activitiesSummary context for accessing a subset of the activities
data. Even though all of these tables are in the same database and
(especially since) they are dependent on each other.

I may be wrong, but my understanding is that if I have a single context
containing activities and venues ( each activity has a venue) then I cannot
get just the venue information without getting all associated Activites also.


For that reason I have seperate models/contexts (dbmls).
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Fri Nov 27, 2009 12:15 pm