ADO.NET :: Intercept/extend Createquery In Entityframework To Allow Global Filter?
Feb 22, 2011
I have not found any way to intercept or override calls to createquery in my datacontext. What I am trying to do is to allow for global filters, i.e. if a user has access to only a subset of entities I would like to filter away these on the lowest level possible. Is there a way to do this? I have tried several apporaches but no one worked out. Perhaps I lack patience or is just plain stupid, but I think it should be possible! So if anyone has any pointers to where
View 2 Replies
Similar Messages:
Feb 11, 2011
I am adding a global action filter on a MVC 3 project.
How can I make it being added on debug but not on release?
View 4 Replies
Jan 30, 2011
I have tried everything, even uninstalling asp.net mvc3, and I can't get HandleError global filter working.I have set up the HandleError filter in the Global.asax:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
Also I have CustomErrors enabled (it does not matter if i set defaultRedirect="Error" or not, I think that is in the docs because is needed for older versions of mvc):
<customErrors mode="On" />
Trying to navigate through the page until the error gets raised, wether you do from localhost or using the hostname, inside the development server or IIS 7.5, it always redirects to a standard status 500 page, instead of my custom Error.cshtml view that I have created in Shared. Here is Error view code:
@model System.Web.Mvc.HandleErrorInfo
@{
ViewBag.Title = "Oooops";
}
<h2>Ooops Something really bad happened!</h2>
Also I have noted that if I create a new ASP.NET MVC3 project and then select "Internet Application" template, and just enabling customErrors in that project, then the HandleError filter starts working just fine, however using the empty MVC3 template does not.I want to clarify, that indeed I can see the error view being processing when debugging, however the browser always display Error 500 page.
View 3 Replies
Oct 28, 2010
I have Create and Edit forms for Categories. Columns are Id, CategoryName, Order, CreatedOn. On Create form I save the values for all but on Edit form I need to change only CategoryName. Below is the code. Problem is that on Edit form only CategoryName field exists which on submit button is passed to Edit Action. Whenever I update Order and CreatedOn becomes null because the values are not returned from form. Someone tell me any good approach how to Updated selected values in EF. Below is code.
Making multiple Get calls. Form is saving fine but I don't like the approach. Need clean approach. Anyone got better solution to thiis?
[Code]....
View 5 Replies
Dec 30, 2010
I am working on my first project with the Entity Framework and am having some difficulty displaying advanced information with the EntityDataSource and a ListView.
For example, given the two entities:
Item
Name
Price
Order
Number
Items <---- Navigation Property to Items contained in the Order
I want to display a list of all orders with a column with the total number of items in the order and a column with the sum of the prices of all items in the order.
I am using an EntityDataSource configured as follows:
<asp:EntityDataSource ID="eds" runat="server" ConnectionString="name=NDSEntities"
DefaultContainerName="NDSEntities" EnableFlattening="False" Include="Items"
EntitySetName="Orders"></asp:EntityDataSource>
In the ItemTemplate of the ListView, I can write the order number as follows:
<%# Eval("Number") %>
I had trouble figuring out how to display a count of items in the order. I tried using Items.Count() function in select statement in the EntityDataSource but that didn't work. Eventually I figured out I could do the following in my ItemTemplate:
<%# Eval("Items").Count() %>
Now I am stuck trying to get the sum of the items. I am stuck here. I have tried using
<%# Eval("Items").Sum(Function(i) i.Price)%>
but I get the following error:
Public member 'Sum' on type 'EntityCollection(Of Item)' not found.
This confuses me because I know that Sum is a method of EntityCollection(Of ).
My two questions are as follows:
Am I getting the item count correctly?
How should I go about getting the sum of the prices of the items?
View 1 Replies
Jul 21, 2010
Im tring to implement some generic logging in the entityframework 4.0 using the SavingChanges event in the entity context.
I want to record details about any create/ update and deleted records including the id of the record being changed (which is always an int identity field). During the update and delete processes I can get the id for the record using
Dim AddedItems = Statemanager.GetObjectStateEntries(EntityState.Added)
For Each entry As ObjectStateEntry In DirectCast(sender, ObjectContext).ObjectStateManager.GetObjectStateEntries(EntityState.Added)
NewLogItem.RecordId = CInt(entry.EntityKey.EntityKeyValues(0).Value.ToString())
Next
But I obviously cannot get the id of the about to be inserted record during an insert becuase it hasn't been written to the database yet, is there a simple way around this?
View 3 Replies
Jun 14, 2010
With ASP.Net 4, is there any way that we can bind web-form controls to entity framework objects?
<asp:TextBox ID="UserName" runat="server" BoundTo="UserName" BindingSource="..."></asp:TextBox>
so just like in MVC I can
form.UpdateModel(userObj),
form.DisplayModel(userObj)
View 1 Replies
Jun 14, 2010
with asp.net 4, is there any way that we can automatically bind web controls (textbox, listbox, check, etc), to EF4 Objects?
View 2 Replies
Jan 27, 2011
SaveChanges can generate an UpdateException when an object added to the ObjectContext cannot be successfully created in the data source. This can happen if a row with the foreign key specified by the relationship already exists. When this occurs, you cannot use Refresh to update the added object in the object context. Instead, reload the object with a value of OverwriteChanges for MergeOption.
In a table, a foreign key column can have a single value multiple times. e.g. DepartmentID foreign key in Users Table: More than one User can have same DepartmentID foreign key.
So how can this cause an UpdateException ?
View 1 Replies
Jan 15, 2010
I would like to call a method in the ObjectContext which returns EntityCollection and have it sorted the way I want by default. For example, Imagine I have the following Category table/class:
CategoryID (PK)
Name
ParentID (FK_Category) foreign key
pointing to CategoryID itself.
(This table is the base for a tree structure of Categories and SubCategories)
Now, in my data model, the public partial class Category : EntityObject has a property which returns all Categories that have ParentID==CategoryID, in other words, EntityCollection<Category> SubCategories.
Alright, now i want to show in my page all the Categories and SubCategories by using Repeater:
<asp:Repeater ID="rptSubCategories" runat="server">
<ItemTemplate>
<%# Eval("CategoryID") %> - <%# Eval("Name") %>
<asp:Repeater ID="rptSubCategoryCategories" runat="server" DataSource='<%#Eval("SubCategories")) %>'>
<ItemTemplate>
<%# Eval("CategoryID") %> - <%# Eval("Name") %>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
Then in code behind, I set the DataSource:
IList<Category> categoryList = new CategoryProvider().GetAll();
rptSubCategories.DataSource = categoryList;
rptSubCategories.DataBind();
Simply and everything works! Except that, rptSubCategoryCategories doesn't gives sorted Categories by Name. The only way I found to do it, is to change its DataSource from:
DataSource='<%# Eval("SubCategories")) %>'
to:
DataSource='<%# ((EntityCollection<Category>)Eval("SubCategories")).OrderBy(p => p.Name) %>'
but I wish I could do something else to have a default sorting so i don't need to call the OrderBy. Something like Attributes like we do in DynamicData, following the tutorial at [URL] Setting the default sort column of an Entity with DisplayColumnAttribute. Unless somebody tells me it's impossible what I want to do.
Using .NET 4.0 BETA 2
View 1 Replies
Jul 6, 2010
I got a problem when getting some data out of my EntityFramework using Linq
Heres my code
[Code]....
Heres the ClientViewModel :
[Code]....
As you can se in the ClientViewModel the Users property is a List
But when trying to compile I get a error saying
Cannot implicitly convert type 'AdminMVC.Models.Clients_Username' to 'System.Collections.Generic.List<AdminMVC.Models.Clients_Username>'
View 2 Replies
Feb 8, 2011
I know there is a couple answered questions on here regarding "request scoped" globals, but I want to nit-pick on something specifically and maybe squeeze some extra enlightenment out of one or two of you.I have an ASP.NET C# Website and a static Dictionary of objects (loaded from DB once on Application start). Each page request will need to do a lookup in the Dictionary (based on a key derived from the request url/etc) and get the appropriate object.The issue is I'm trying to maximize efficiency by reducing the lookups to the Dictionary per Request. Doing just a single lookup within a Page itself is easy enough and I can pass the object to sub controls, etc too.. but global.asax is separate from the Page and it also needs to use the object (in Application_BeginRequest and Session_Start).
So is doing a Dictionary lookup once in Application_BeginRequest, once (when necessary) in Session_Start and once in the Page negligible speed wise, even if there are many requests coming in every second?I would like it if I could just have a Request scoped global variable that I can easily call upon.. the only one I see available though is HttpContext.Current.Items and that is a Dictionary itself.Am I beingridiculously nit-picky with my concern over efficiency? or will these milliseconds (nanoseconds?) get me in the long run when more and more requests are being made?
PS. I currently only have around 100 objects in the Dictionary although this may increase in the future.
View 2 Replies
Oct 2, 2010
I'm working on a project which is using EntityFramework 4 and I am using the entity objects as my business objects. I ran into an issue recently where I had a context declared in a using statement in a user control. The method the statement was in returned an entity object which got used in another control. So I had to detach the entity then attach it to the new context in the other control. I would like to avoid this if possible. What I'm thinking is I would like to declare a context in the master page and then pass that to any page/usercontrol that needs it so they are all using the same context and I don't have to write all these using statements.
My questions are these:
1) is it a bad practice to declare a context on Pre_Init/Page_Load and then dispose of it on Page_Unload?
2) if it is what is the best practice for handling them?
3) if I do go the route of declaring the context in the master page what is the best way to pass that to the pages/usercontrols?
View 1 Replies
Feb 11, 2010
I am having some issues with my base class inheritance. I am currently employing Table per Type Inheritance for the following tables:
Database:
Members Table
- Member ID (PK)
- First Name
- Last Name
- Email
- ...
Students Table
- Member ID (FK)
- Credits
- Notes
- ...
Instructors Table
- Member ID (FK)
- Biography
- Office Hours
- ...
My Entity Data Model defines "Member" as the base class for both Students and Instructors, since members can be both students as well as instructors simultaneously. The problem, however, occurs when I attempt to get a list of Members objects. Because the database contains members who are indeed students AND instructors, the following exception is thrown:
All objects in the EntitySet 'CountyCollegeEntities.BaseMembers' must have unique primary keys. However, an instance of type 'CountyCollege.NET.Administrator' and an instance of type 'CountyCollege.NET.Student' both have the same primary key value, 'EntitySet=BaseMembers;ID=10016'.
I am beginning to think that I made a mistake by building these classes to inherit from Member although it has been ideal up until this point. But before I start ripping up all my existing code to remove this inheritance, I thought I would see if anyone has any tricks that would make this work. Any advice as to either how I can get around this error or a more appropriate way to structure my classes would be very much appreciated.
View 2 Replies
Oct 31, 2010
I need good css for Gridview just like the mac css
can we provide the filter functionality to gridview like the excel filter.
View 3 Replies
Jan 1, 2010
In securing actions/controllers, do I have to create a custom filter or use MVC built-in filter?
To use the built-in attribute Authorize() on an action/controller or create a separate class that inherits the ActionFilterAttribute which has a method (OnActionExecuting) to override and do the authentication there?
View 2 Replies
May 2, 2010
Cannot seem to find a good fit for my question so I will ask here.
Does Asp.Net 4.0 solve the problems with using Views with EntityFramework is not able to recognize primary keys.
View 2 Replies
Mar 9, 2010
In my organization we use nested groups. For a particular usage, we have a group (let's assume that the group name "kuku"), and the names of all the nested groups under it contains "kuku" as well.
We may assume that no other group in the LDAP has "kuku" in the name.
I need to create a filter which will return all the users which belong to one of the "kuku"s group.
Obviously, using this filter will bring only the head kukus
(&(&(objectclass=user)(objectclass=person))(memberOf=CN=kuku,cn=...rest of the group DN...))
How can I use wild card to fetch all users which belong to any kuku?
For example: (&(&(objectclass=user)(objectclass=person))(memberOf=CN=.*kuku.*))
View 1 Replies
Mar 17, 2010
I have decorated my base controller with a couple of action filters. They work fine.
One of those filters sets up the request - does things like set the culture based on the domain, etc.
I also have a handful of actions that require authorization using the Authorize attribute.
My problem is that when an user attempts to request a page they are not authorized to access, the authorization filter kicks in and redirects them to a page telling them that they cannot vie the page.
The issue is that the action filters never run so the culture and other request data is never set. This effectively causes language to be wrong in the view and other data to be missing.
I know that authorization filters run first but my question is this: How can I design this such that I can ensure that certain methods are always run before the view is returned, regardless of the authorization.
View 1 Replies
Feb 10, 2010
I want to intercept any postbacks in the current page BEFORE it occurs . I want to do some custom manipulation before a postback is served. how to do that?
View 5 Replies
Jan 13, 2011
I have a control used in our CMS and we don't have the source code for it, what I would like to do is change the rendered output of this control.
Now, I could have a check in my base Page class that checks if the control is being used on the page and then change the html that needs to be altered, but that seems a bit excessive for just 1 usage.
So is there any other way of changing the behaviour of the control without the source code? I'm thinking not other than the way described above.
View 1 Replies
Feb 14, 2011
I am implementing HttpModule for compressing request.Below is the codee for HttpModule:
public class Global : IHttpModule
{
public void Init(HttpApplication app)
{[code]....
It's able to intercept and compress js and css in the development web server but when i run it from IIS 5.1 it is not able to compress js and css files.
View 2 Replies
May 28, 2010
I would like to generate a 401 page if the user does not have the right permission.
The user requests a url and is redirected to the login page (I have deny all anonymous in web.config). The user logs in successfully and is redirected to the original url. However, upon permission check, it is determined that the user does not have the required permission, so I would like to generate a 401. But Forms Authentication always handles 401 and redirects the user to the login page.
To me, this isn't correct. The user has already authenticated, the user just does not have the proper authorization.
In other scenarios, such as in ajax or REST service scenario, I definitely do not want the login page - I need the proper 401 page.
So far, I've tried custom Authorize filter to return ViewResult with 401 but didn't work. I then tried a normal Action Filter, overriding OnActionExecuting, which did not work either.
What I was able to do is handle an event in global.asax, PostRequestHandlerExecute, and check for the permission then write out directly to response:
if (permissionDenied)
{
Context.Response.StatusCode = 401;
Context.Response.Clear();
Context.Response.Write("Permission Denied");
Context.Response.Flush();
[code]....
First of all, I'm not even sure if that is the right event or the place in the pipeline to do that.
Second, I want the 401 page to have a little more content. Preferably, it should be an aspx page with possibly the same master page as the rest of the site. That way, anyone browsing the site can see that the permission is denied but with the same look and feel, etc. but the ajax or service user will get the proper status code to act on.
View 3 Replies
Aug 25, 2010
does a action filter override a controller filter?
View 2 Replies
Feb 17, 2010
I am working on a tool which audits access to existing web application. Existing app does not have any hooks in place, but my plan is to inject an IHttpModule by modifying web.config and log whatever I need to log during EndRequest event.
What I'm struggling with right now is: I cannot intercept what is application writing to an output stream. I need to know what output does the application send to the client. Originally, I hoped I could run a code in BeginRequest to replace HttpContext.Response.OutputStream with a stream of my own, which would be flushed to original stream during EndRequest, but the stream only has a get accessor, so I cannot replace it.
I could of course use reflection to assign to private member of HttpContext.
View 2 Replies