This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello! I think I've found small issue with views. When I try to use this (RandomScreencast is a view which returns random item from WebsiteScreencast table):
I'm getting error:
but when I do this using this:
it works. Regards |
|
|
Is PluralizeTableNames set to true? If it is, LightSpeed will try to pluralise the entity name to get the table or view name, so it will look for a view called RandomScreencasts instead of RandomScreencast. However, specifying a ViewName in the query, or a TableAttribute on the class, overrides the inferred name, which is why your second example works. There are various ways to address this: 1. Rename your view to RandomScreencasts, so it uses the same pluralisation convention as your tables. 2. On your RandomScreencast class, specify the attribute [Table("RandomScreencast")]. (If using the designer, set the Table Name property.) 3. Use your second example. This has the effect that what you get back is a WebsiteScreencast object, so it will play nicely with other WebsiteScreencasts (e.g. object identity) and you don't need to define a whole new class just to get view access. Usually if the view is just returning rows from the WebsiteScreencasts table (e.g. just ordering or filtering or whatever) then we would recommend using Query.ViewName. Use a new, view-backed entity type only when the view doesn't map directly to a table (e.g. the view performs a join), and therefore should materialise as a conceptually different kind of entity. You can associate views with an entity type in the designer by dragging a view onto an entity. This will generate a property in the unit of work so you can still use your first, more convenient syntax but get true WebsiteScreencasts back: WebsiteScreencast randomScreencast = unitOfWork.Current.RandomScreencasts.First(); |
|