Examples with Entity Framework? #3259
-
I'm into the MVC example but it has a DAL which doesn't interest me at all. Any good examples of this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
In my RodentList I have the following code taken from the MVC example where I attempt to switch over to EF. The commented out line is the orginal from the example:
I can successfully call this from the controller but is errors because in my code RodentInfo is a CSLA business object. In the sample code the object is an 'Entity' which is just a very simple object. If I convert my RodentInfo from a CSLA business object to a simple object the code works and the FetchChild is called. Maybe CSLA objects cannot be used in Code First EF scenarios? It looks like I'm trying to use business objects to define the database, set as the collection pulled from the database, and then cast as full CSLA versions of themselves....so maybe that is just bad. |
Beta Was this translation helpful? Give feedback.
-
Gregg, Although I use EF extensively, I only use database first and DALs. I haven't had any problems with CSLA accessing EF using database first. I have used dataportal methods and those work too. But, I'm not sure about the code first approach. That's a bit too iffy for me--as I come from a DBA background. |
Beta Was this translation helpful? Give feedback.
-
@GreggThelen does your child class's data portal operation inject a DAL as well? I would expect that it would. The parent type should inject a DAL type to get its own data, and then would inject a child data portal to interact with child types. The child types obviously need data as well. The child types can get their data from the parent (if the parent uses the DAL to get the entire entity graph), or the child types might need access to the DAL (via injection) to interact with the DAL as necessary. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the prompt responses. I was trying to mix EF Code First with CSLA buiness objects, and while I think this is possible I don't think it is advisable. I was running into situations where the table name in EF ('Users') was colliding with object names ('UserInfo', 'UserEdit'). Annotations can work around this but the CSLA business object ends up serving two roles (database definition, business object) and that is a confusing mess. I broke out my EF into a separate data access project and my business objects into their own project and once that was done the problems became clear and were quickly overcome. The separation of concerns is always the way to go. |
Beta Was this translation helpful? Give feedback.
@GreggThelen does your child class's data portal operation inject a DAL as well? I would expect that it would.
The parent type should inject a DAL type to get its own data, and then would inject a child data portal to interact with child types. The child types obviously need data as well.
The child types can get their data from the parent (if the parent uses the DAL to get the entire entity graph), or the child types might need access to the DAL (via injection) to interact with the DAL as necessary.