I am learning unit of work at google.
But most of the example I get is about with unit of work with DbContext.
So please could anyone give me example of Unit of work with ObjectContext.
[Just my thinking, May be not correct.]
I don't like code first pattern because it need me to write properties classes(with get set methods) myself.
But by using edmx file with objectContext, i don't need to create properties classes which take time.
There are plenty of articles on this.
Entity Framework POCO (EF4): Generic Repository and Unit of Work
Prototype
Entity Framework 4 POCO, Repository and Specification Pattern
These abstractions may not fit to your problem exactly. So understand the concepts behind the Entity Framework before going into making abstractions.
Related
I have done a web site project in PHP using mySQL at school, which was not object oriented but that was in a manner on which I want to display my content. Then I changed the same project into object orientated classes where I use same CRUD queries in functions of that classes and they interact with a DBWrapper class. Or can say, I just cut the php content and pasted it into the functions and and call that functionality through object. that all was done without documentation. But now i am making a project in .net with documentation how ever its a web based app actually and i have the idea of getting data from database trough queries and o of course c# is different but CRUD is something which is similar in any language. so as i had decide first this thing will display and from thing the next this thing will display etc. about codding than how should i know my class diagram is the same as what i am getting and what that actually is. because i will connect both classes as i wnt to display . and plus is Do we write object of other class as an attribute of second class if that is going to use in it.
Most class diagrams I've seen and made include only the business model entities. Most of the time UML diagrams are used to communicate and document the workings of the system. I like to think of them as pseudo-code.
Please refer to this other question as well: https://softwareengineering.stackexchange.com/questions/190429/what-classes-to-put-exactly-in-a-class-diagram
However, if you feel your implementation ended up with a lot of helper classes then it's probably good to review your system's structure to make sure you are coding "object oriented". Actually making the class diagram is supposed to help you realize what you can improve.
I suggest you also take a look at design patterns. This link might be useful, as you mention experience with C# http://www.dotnettricks.com/learn/designpatterns
Please pardon the long-winded title to this post.
Basically, I have an entity model that was generated by Entity Framework 5 using the Database First method. Now I would like to develop those POCO entity classes by adding validation logic and anything else I might need to go in there. The problem... (and this is so glaring I can't believe I couldn't find any answer to this on the web)... is that any time my database schema should change and I use the "Update Model from Database" command from my model diagram, the POCO classes are re-generated and all custom code is lost.
As far as I understand, the "domain model" layer in an MVVM application is largely comprised of what EF generates (in database first approach), plus validation (perhaps implementing the IDataErrorInfo. But if this was the right way to do it, why would this be wiped away when using database-first model updates?
What am I missing?
Thanks
You should use partial classes. That is why they are there.
If you want to know the basics see this short example:
http://www.dotnetperls.com/partial
Here is more on partial classes from the msdn:
http://msdn.microsoft.com/en-us/library/vstudio/wa80x488.aspx
If you want to use your own namespaces in the genarted code, you can refer to this SO question:
Entity Framework 5 partial classes not working
I want to replace ORMLite to EF5, and please don't ask me why :P ... So I searched around the net and have no luck finding much information on how to actually do this.
Do I need to rewrite ORMLiteConnectionFactory into EFConnectionFactory that registers in global.asax.cs? It seems like a lot to implement and very complex because it is linked to IOrmLiteDialectProvider OrmLiteConfig and all that, and it doesn't seem right because SS normally have a simple answer to all questions. For example, it is rather easy if I want to change Funq to another DI provider.
Is ORMLite the fixed choice of weapon or is this a flexible option that I can tune? Please help.
For all intents and purposes you're better off pretending OrmLite doesn't exist. OrmLite simply provides extension methods off ADO.NET's raw IDbConnection interfaces which works similar to (and why it is able to be used alongside with) Dapper and other Micro ORMS.
Entity Framework in contrast manages its own heavy abstraction that's by design not substitutable with other Micro ORMS, so you shouldn't attempt this route.
Simply ignore OrmLite exists and use Entity Framework as you normally would. Last I heard EF doesn't play too nicely with IOCs so you probably have to resort to the normal case of instantiating a new EF DataContext whenever you want to use it.
Over the years, I've investigated a lot of ways to use code generators and MDD. I've always felt that something is lacking: Patching and changes to the model at runtime.
Patching: If you have a code generator, all your classes should look the same. Now you have a single exception. All code generators so far would require that I modify the template or the template engine to make this work.
Wouldn't it be better if I could apply patches to the result of the code generation step to fix the exceptions?
Well, it depends on how you build your model. If fact, it depends on what code generator you are using, its approach, and what it lets you do.
Creating an exception to a rule (model) is more or less against the nature of MDD, unless the applied modeling approach allows you to add exceptions as modeling entities.
I think ABSE is the only modeling approach that accepts "custom code" as a first-class entity, just like a text or an integer. If you create a template that contains a "CustomCode" parameter, you can later add your exception code only when necessary, without breaking your model rules. This can be used to add or replace code. You just need to specify it in your template.
AtomWeaver is a free implementation of the ABSE modeling methodology.
MDD doesn't work because it is based on a view of the domain and not the entire domain. I mean that usually MDD take an XMI in entry coming from an UML diagram. The problem is that this diagram is only a view of the domain and therefore you have many alternative and the real world is a mot more complex specially at deployment stage.
The only company which has provided me real value in my project was Omondo with EclipseUML. EclipseUML doesn't try to do MDD but create UML at diagram level live synchronized with code. Deployment is made using stereotypes which are added in the java annotation in the code. I can therefore model and if I add deployment stereotypes then my application can be deployed immediately/ If I manually change my code, then my model is refactored and all my views updated. If I want to add a documentation then I just add notes in the metamodel. These notes are live available when I click on each element. No more printed documentation needed because live navigation, dynamic views creations etc...
My EclipseUML model is always up to date, and I can deploy it immediately because Java annotations are lived synchronized between the model, the metamodel, the diagrams and the code. Really cool :-) :-)
Im new to subsonic and generally this was of programming, i usually develop from a rad perspective so using the visual studio dataset designer, but i wanted to start looking at developing n teir approach.
Ive never used a business logic layer, (naughy) normally my code behind takes care of validation so to speak aswell as general page level validation.
How can i generate my business logic, do i create a partial class of one of my classes and then add the business logic into this? and how would this look? just so i have an idea.
Any exmaples or advice would be greatly appreciated.
Thanks
Dan
The big gotchya with SubSonic is that it generates classes from database tables, there is a 1-to-1 correspondence between the two. That makes the classes SubSonic generates quite unsuitable for use as business objects, because it would tie your business layer very directly to your database structure. This is a bad thing (in nearly all scenarios that come to my mind, anyway).
SubSonic is a query tool and little more. It most certainly is not an ORM.
With that in mind, I believe the correct way to create a Business Logic Layer is to write your own business classes, and write Repository classes to manage loading and storing the data. But use SubSonic only internally to the Repository classes to handle the actual persisting of your data to the database.
If you use the SubSonic generated classes throughout your project you will find you are most likely doing it wrong, and the first significant change to your DB schema will illustrate that nicely (or .. not nicely).
In fact, I would recommend quickly moving into learning a real ORM like NHibernate or Entity Framework. They bring you much farther down the Happy Path, whereas SubSonic still requires one to do much of the Data Layer implementation themselves.