How mature & felxible is the Entity Framework's code-first library? - asp.net

I'm getting ready to do a small, brief architecture spike using the EF code-first approach, introduced by Scott Gu here and here. Before I do, I'd like to know whether it will be worth it. Currently I have a project that uses the EF POCO Generation template, and I'd like to investigate the advantages I can get out of switching to a more pure POCO strategy for the domain model. Particularly, these are the things I'm interested in:
Avoiding automatically-generated partial classes with collection fixup methods, and being able to concentrate on essential domain object code without worrying about association persistence.
Avoiding having to transform templates every time I want to add an artifact to the model.
Still being able to have some control over the strategy of table persistence (locations of ComplextTypes, table-per-type versus table-per-hierarchy, etc). These aren't as important as the other 2 concerns.
The most recent version I could find of this was the CTP4, released summer 2010. Is this the most current version?
What are the cons of choosing this approach, using this particular library? Can you recommend any other concerns I should investigate in the spike?

Go through these tutorials and check this blog about some additional topics like inheritance - it will give you pretty good overview of Code First in CTP5 which should be close to final version as stated here:
CTP5 will be our final preview of Code
First and the simplified API surface
(DbContext) before we offer a full
supported production ready release in
Q1 of 2011.
I think all three points you mentioned are satisfied by current version.

Related

MVC Testing in VS 2010 vs VS 11

Over the last 2 months, I've been trying to learn the new MVC framework. After getting my head around all the object oriented concepts, I created a test site using MVC3, EF4 w/ DbContext, and ASP.Net Membership provider. All was going pretty well. Then, I decided to dive in and learn testing, starting with Unit Testing.
After 2 weeks of banging my head against my keyboard, I now feel as frustrated as can be. I've gone through tons of video tutorials (TekPub, Plural-sight), online tutorials (ASP.Net, Microsoft, etc..etc..) and plenty of StackOverflow questions/answers. I now sort-of (ha!) understand Loose Coupling, Dependency Injection, Respositories, Interfaces, Stubs, Mocks (yes, I read the Fowler article many times), Shims, lambdas, refactoring...the list goes on and on (...and on.). I've looked at Ninject, Structuremap, Moq, TypeMock, JustMock, nUnit, xUnit, etc...
So I know there are a bunch of ways to skin this cat. Now I see that VS11/MVC4 is coming out and they have this thing called Fakes which seem to be a good option for static methods like the Membership stuff.
My question:
I want to test my MVC EF4/DbContext/Membership application. Most of my pages require an authenticated user [Authorize] and thats before I even get to the actual method to be tested.
If you were just starting out (like me), what is the simplest and easiest route to testing my CRUD application? I don't necessarily like having a DI framework running on the production side (just another thing that might go wrong) and I find the fracking things are confusing as all get out.
I could upgrade to VS11/MVC4 and try the Fakes approach. Appears to be slightly simpler but still seems like I need all the Respository/Interfaces for EF stuff.
Or would you just chuck it and use an Integration Test tool like Selenium (which is what I had to use before with Forms based development)?
Any suggestions are greatly appreciated. Sorry if this is a lousy question but I'm hoping for a ray of light here...
For all versions of mvc or programs its almost same way of testing.
You sould have most of your logic based on interfaces.
this will allow you to separate concerns and unit test anything you need also this will give you posiibility to fake (create fake implementations) or mock (create class on runtime that will represent logic you want, using Mock, or Rhino Mock) the logic.
You can read more about basic unit testing here:
http://msdn.microsoft.com/en-us/magazine/dd942838.aspx
also i would recomend you have a look on book where Steven Sanderson has example application including unit testing of most parts.
http://www.amazon.co.uk/Pro-ASP-NET-MVC-Framework-ebook/dp/B005PZ07US
Here you have introduction to MOQ
http://www.codeproject.com/Tips/182847/An-Introduction-to-MOQ
You have alternative such as rhino mock:
http://ayende.com/blog
and some examples:
http://daysincode.blogspot.com/2012/06/examples-of-mocking-with-rhino-moq.html
Of course everything here leads to : http://msdn.microsoft.com/en-us/magazine/ekstremalna-przerobka-asp-net--czesc6-podzial-obowiazkow.aspx

How to structure a proper 3-tier (no ORM) web project

I m working on a legacy web project, so there is no ORM(EF,Nhibernate) available here.
The problem here is I feel the structure is tedious while implementing a new function.
let's say I have biz Object Team.
Now if I want to get GetTeamDetailsByOrganisation
,following current coding style in the project,I need:
In Team's DAL, creat a method GetTeamDetailsByOrganisation
Create a method GetTeamDetailsByOrganisation in the Biz Object Team, and call the DAL method which I just created
In Team's BAL, wrap up the Biz object Team's method in another method,maybe same name, GetTeamDetailsByOrganisation
Page controller class call the BAL method.
It just feels not right. Any good practice or pattern can solve my problem here.
I know the tedium you speak of from similarily (probably worse) structured projects. Obviously there are multiple sensible answers to this problem, but it all depends upon your constraints and goals.
If the project is primarily in maintenance mode with very no new features being added I might accept that is the way things are. Although it sounds like you are adding at least some new features.
Is it possible to use a code generator? A project I worked on had a lot of tedium like this, which apparently was caused because they originally used a code generator for the code base which was lost to the sands of time. I ended up recreating the template which saved me a lot of time, sanity, and defects.
If the project is still under active development maybe it makes sense to perform some sort of large architectural change. My current project is currently in this category. We're decoupling code and adding repositories as we go. It's a slow process that takes diligence and discipline by the whole dev team. Each time a team takes on a story they tax that story with rewriting some of the legacy code in that area. To help facilitate this we gave a presentation to the rest of the team to get buy-in and understanding. We also created some documentation for our dev team that lists out the steps to take and the things to watch out for. In the past 6 months we've made a ton of progress. We don't have the duplication you speak of, but we have tight coupling issues which makes unit testing impossible without this refactor.
This is less likely to fit your scenario, but it may also be a possibility to take certain subset of features and separate those out into separate services that can be rewritten using a better platform and patterns. The old codebase can interoperate at the service layer if needed. You likely make changes in certain areas more than others, so the areas of heavy change might be top priority to move to a dedicated service. This has the benefit of allowing you to create a modern code base without having to rewrite the entire application from scratch all at once. This strategy is what Netflix has done to rewrite their their platform as they go and move it to the cloud.

Design and Modelling for DexExpress eXpressApp Framework

The DevExpress XAF does much basis work for you, it creates a database based on your business objects, and dynamically generates a UI based on these, with basic functions like add, delete, sort etc. already present.
This leaves me wondering how to go about properly designing and modelling an application built on this framework. I could only model my business objects, or I could identify functions provided by the framework and include them in a details model down to sequence diagram level, but so much is being done by 'external' calls that I feel I would be wasting valuable time.
I am hoping someone with experience modelling application designs for this specific framework can give me some advice on what areas I should focus on.
As for DC, as Leon mentioned above, it has many benefits compared to the regular persistent classes. If all goes according to plan, we will release the Domain Components technology in the near future, and resolve all the remaining issues with it.
If you feel that it is hard to learn, please let us know the most difficult parts you experienced. We will be glad to review them and possibly make the things easier for you and other users.
P.S.
I apologize for the delay in responding; I was on sick leave. You will receive more timely responses if you post your questions in the DevExpress Support Center.
#ProfK:
Am I correct that you are looking for something like visual designer for your business models?
If so, then I am afraid that XPO (XAF) does not currently provide such a functionality. However, you can use free third-party tools for modeling, such as Liekhus ADO.NET Entity Data Model XAF Extensions
I hope you find this information helpful.
I'm using XAF for almost two years now and I'm very happy with it. Developing an app is very quick, nice architecture, both Win and Web the same time and great UI. As with all frameworks, it has a learning curve, but if your already familiar with DevExpress controls that it's not very hard.
As Dennis mentioned, most behaviour can be overriden or extended. Regarding your modelling question, if think an important choice you have to make is whether or not you will use their Domain Components technology. Basically they have 2 ways: the old fashion way by inheriting from the XAF or XPO base classes or by using DC. DC allows a clean separation in modules and allows multiple inheritance. They can do that by generating classes runtime, but it still has some issues.
And the framework comes with a Business Class Library, a set of common classes which may be useful.
When I get stuck or cannot find the answer myself, I always use their fantastic Support Center. Most issues I ran into were already asked and answer on that site.
Briefly, each XAF application consists of Modules. There can be standard (system) and extra (user-defined) modules. Each Module can contain business objects, so-called Application Model customizations, Editors, Controllers, and Actions to provide additional business logic, customize UI and provide interaction between framework parts. You can model and customize your application on each level listed above, including but not limited by the underlying framework's metadata and data store ones. You can find more information about the framework's architecture here:
http://documentation.devexpress.com/#Xaf/CustomDocument2559
I should emphasize that it is possible to override behavior of almost every part of the framework. For instance, create your own editors for detail and list forms, override certain standard controllers, etc.
If you experience any further difficulties with our framework, feel free to contact us through our Support Center. We will be always glad to not only answer you questions, but advice a certain technical or design solution, provide some example code, etc.

to learn entity framework, how do i use it in a pet project?

i want to learn entity framework. i started with some EF tutorials and i also know little about linq to sql.
i want to learn through a pet project. project should be in three layers. web forms (prez), data layer(c# lib), bussiness layer(c# lib). Project can be any, any functionality. just want to learn how to use EF in diff. layers and in UI.
can anyone guide me how do i start to do layering? help me to learn how should i use EF objects from DAL layer to BL and then UI.
I am confused as all tutorials shows direct binding of EF to EF datasource in UI and with controls.
thanks a lot.
In order to maintain a layered architecture I would create partial classes of the generated EF Classes. In these classes I would have methods I could use with objectdatasources in the presentation layer. Thats how I do it anyways, hope it helps!
A couple of things I would recommend:
Rob Conery (with occasional guests) put together a video series on building a storefront site using ASP.NET MVC. He used LINQ-to-SQL, not Entity Framework, but I don't think the difference is significant to what you are interested in learning. One nice thing about this series is that he walks you through the various design decisions he makes, and even backtracks when he later feels that one of them was wrong. Another is that, in addition to MVC and LINQ-to-SQL, he also explores some other development concepts such as inversion of control and test-driven development.
Martin Fowler's book Patterns of Enterprise Application Architecture is a great resource for this sort of thing. He lays out the different patterns that are available in each tier of your application and discusses how to use them and when each is appropriate. Fowler's writing style is friendly and easy to read, and a lot of the patterns in his book are prominent in the vernacular of the software development world today (e.g. Repository pattern, Active Record, Unit of Work).
Hope this helps!

robust server side dynamic form engine for ASP.NET

I've recently implemented a simple dynamic forms engine that uses dynamically loaded ASP.NET controls in concert with an EAV schema to handle the variable nature of the data model. The business was sufficiently satisfied with the end product for a time, but is now clamoring for much more complex dynamic forms:
Field visibility is tied to the values of other form fields
List of drop down possible values tied to the state of other form fields
Enforcement of various business rules across the form: i.e. Value of FieldA must be no greater than FieldX + 30 days, assuming FieldX is not null, blah blah
Other complex inter-field dependencies and business rules
As you might imagine, I'm looking for an off the shelf solution since rolling such an engine from scratch seems tedious, time consuming and not really part of our core business. Ideally, I want complete ASP.NET framework (MVC or WebForms) that encompasses all layers (Business Logic, Presentation Layer and Persistence). Beggars can't be choosers, however, so I'd make do with a framework that only dealt with Business Rule definition and evaluation. Furthermore, I'm looking for a strictly server-side solution since my hands are tied by a strict policy that disallows any dependence on client side plug-ins.
XForms seems like a perfect fit, but the only mature implementations I've found are based on Java (Orbeon) or Django (Chiba). The other XForms implementations I've found have some kind of dependence on client-side plug-ins.
I'm open to using Orbeon if I can figure out a way to integrate it with an ASP.NET application, but I've see no actual examples of such a hybrid implementation.
I looked briefly at Microsoft Office InfoPath, but it doesn't seem nearly robust enough to handle the kind of complex scenarios I need to implement.
All ideas welcome!
You should have a look at betterform (http://betterform.de) too. It's a successor of Chiba and has many improvements in comparison to the original Chiba. It is open source and hosted at sourceforge as the original product.

Resources