C# - Map Class To Get The Db's Records With A Custom Method?
Apr 1, 2010
I'm developing a website with ASP.NET MVC, NHibernate and Fluent NHibernate and want to know how can I customize my Map to get records using a custom Method.
My entities:
public class ImageGallery {
public virtual int Id { get; set; }
public virtual string Titulo { get; set; }
public virtual IList<Image> Images { get; set; }
ublic virtual bool IsActive { get; set; }
}
public class Image {
public virtual int Id { get; set; }
public virtual ImageGallery ImageGallery { get; set; }
public virtual string Low { get; set; }
public virtual bool IsActive { get; set; }
}
My Fluent NHibernate Maps:
public class ImageGalleryMap:ClassMap<ImageGallery> {
public ImageGalleryMap() {
Id(x => x.Id);
Map(x => x.Titulo);
HasMany(x => x.Images)
.KeyColumn("ImageGalleryID");
Map(x => x.IsActive);
}
}
public class ImageMap:ClassMap<Image> {
public ImageMap() {
Id(x => x.Id);
References(x => x.ImageGallery);
Map(x => x.Low);
Map(x => x.IsActive);
}
}
And, a method on my ImageRepository class:
public IList<Image> ListActive() {
return this.Session.CreateCriteria<Image>()
.Add(Restrictions.Eq("IsActive", true))
.List<Image>();
}
If I create an object this way:
ImageGallery ig = new ImageGallery();
I can access my the Image's list using:
foreach(Image img in ig.Images) {
...
}
However, ig.Images give me access to all images records and I would like to access just active records (or another criteria), using ListActive()'s repository methods.
View 1 Replies
Similar Messages:
Apr 21, 2010
I have created my own custom role provider class "SGI_RoleProvider" and configured properly.
Everything is working fine.
Suppose that I have added a public method say "SayHello()", then how can i call that. Because if i am using Roles then the method is not displayed. If i am forcefully using that Roles.SayHello() then compiler gives the error.
how can i call this. Because creating a new instance of SGI_RoleProvider is meaningless.
View 1 Replies
Apr 27, 2016
This is the query I am running in DB:
select UM.USER_NAME, RM.ROLE_ID, RM.ROLE_NAME
FROM [MICommonDB].[dbo].[ROLE_USER_MAPPING] as RUM
join [MICommonDB].[dbo].[ROLE_MASTER] as RM ON RM.ROLE_ID=RUM.ROLE_ID
join [MICommonDB].[dbo].[USER_MASTER] UM ON UM.USER_ID = RUM.USER_ID
where UM.USER_NAME='useruser'
which is giving me proper result(i.e., 2 records) when running in SQL server.
Now I have created below method in a class with same query (I am calling this method inside Controller):
public IEnumerable<RoleUserDO> getRoleNameByUserName(string userName)
{
IEnumerable<RoleUserDO> strResult = null;
strResult = (from RUM in oDBContext.ROLE_USER_MAPPING
[CODE]..
but it returns only 1 record instead of 2 records(when compared with DB query)
View 1 Replies
May 17, 2010
I am creating custom server control. I have two classes in project. One is main class that render control and another will be used to render content based on condition.I just want to know how to render content from other classes in main class.For example. This isjust an example.My main class code
[Code]....
My TopLeftPane class
[Code]....
My page code on page load event
[Code]....
When I run the page, Header title always getting null. This is a just sample code. I will have more than 20 classes so I dont want to write a code in main class to render whole control.I hope all of you understand my problem.
View 3 Replies
Apr 23, 2010
I have several custom classes that derive from a common base class so they share several members in common. I would like to be able to pass objecs from any of these three classes to a function that will "look at" common properties. However, it seems there is a catch 22 -- When I try to access a member (.FirstName) of the passed object, the computer reports an error that it thinks the member doesn't exist.
It seems to be a sort of contradiction -- since I didn't declare the type, the computer can't confirm existence, but it seems that it should have to take it on faith since the generic character of the type is specified by the code. Possibly there is something I don't know about that would fix this. I'm showing VB code for what I have so far. I went ahead and hardcoded an instance to confirm that the object exists and has the needed property. I commented out the line that had the code that resulted in the computer reporting an error.
[Code]....
View 2 Replies
Jan 19, 2010
is it possible to call a custom method or class before accessing webmethod from pageMethods ?
View 2 Replies
Oct 18, 2010
I have an ObjectDataSource that I want to perform updates using a business entity i.e. Type="Object"). Since the values for the entity are within a user control, I have stored a reference to the control in Session and in the updating event, set the new instance to the value of the entity from the user contol property (which also pulls values from the form viaother properties of the control):
Protected Sub MasterDataSource_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles MasterDataSource.Updating
Dim entity As New Login()
Dim accountControl As AccountInfo = TryCast(Session("AccountCtrl"), AccountInfo)
entity = accountControl.Entity
e.InputParameters.Add("entity", entity)
End Sub
And here's the markup for the datasource:
<asp:ObjectDataSource ID="MasterDataSource" runat="server" EnableCaching="true" CacheDuration="10"
SelectMethod="SelectAll" UpdateMethod="Update" TypeName="Data.DAL.LoginDAL">
</asp:ObjectDataSource>
My question is, how can I get the update method to pass this entity to the update method in my BLL class? It seems the Update method requires an ID or reference to the original object to use in determining whether any changes have taken place, but I don't really want to do this. In other words, I just want to use the Update event on my ObjectDataSource to pass my entity to the method ("Update") I set as a property and then let this business method handle the update of the data. Shown below, is the BLL update method I want to call:
Public Overloads Function Update(ByVal entity As Login)
If entity Is Nothing Then
Throw New ArgumentNullException("entity")
End If
MyBase.Update("UpdateLogin", entity.Username, entity.Password, entity.FirstName, entity.LastName, entity.Role, entity.Region, _
entity.Email, entity.Title, entity.TierID, entity.Street, entity.City, entity.State, entity.Zip, entity.Mobile, entity.Phone, entity.Fax)
End Function
When I try to call this as it stands now, I get an error: ObjectDataSource 'MasterDataSource' could not find a non-generic method 'Update' that has parameters: ID, entity. Previously, I'd set up a long list of parameters of basic data types (string, int, boolean), but this is rather cumbersome and I was hoping to use an entity for this (FYI, I also got the same type of error when I tried this approach, but with the ID as the
last parameter in the list). Perhaps what I'm doing here is atypical to how the ODS is normally used?? Has anyone done something like this successfully?
View 1 Replies
May 12, 2010
I have the following page
[Code]....
Currently, only GenericOfflineCommentary's ExtractPageData() is firing. How can I modify this to first run OfflineFactsheetBase's ExtractPageData() and then GenericOfflineCommentary's?
edit: I'm trying to avoid having to call base.ExtractPageData() in every implementor.
View 2 Replies
Jun 24, 2010
I have a WindowsForm that has a DataGridView that shows output of my app. The class with the button is DriveRecursion_Results.cs. I want it so that once the button is pushed by the user, my method FileCleanUp() in my SanitizeFileNames class is called. I'm not quite sure how to do this though.Here is the code for both classes:
public partial class DriveRecursion_Results : Form
public DriveRecursion_Results()
InitializeComponent();
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
[code]...
View 1 Replies
Feb 15, 2011
I'd like to inherit all my controllers from a custom base class that I write myself. I can change the line every time I add a new controller, but it would be nicer if I could somewhere specify the default value that gets set there. That way I wouldn't need to worry about forgetting this, and other people who get added to the project later on would have an easier time.
View 3 Replies
Nov 29, 2010
I am creating a custom control by inheriting a server control, say LinkButton. There are properties like "BorderColor" available in LinkButton. Let's say, I don't want this particular property to be available when I create an instance of the custom control.
I want to completely hide this particular property (I don't want to override it but disable it.)
My code is as follows:
[Code]....
View 3 Replies
Jul 8, 2010
I'm building an n-tier application, with the web client and the class library separate. I'm also using the factory pattern of development, using interfaces to act as containers for different objects they are associated with. The problem I'm expreriencing is that I declared a public interface class in the class library and I can create an instance of it in in my aspx pages but whenever I declare it in my custom control code-side, i get an error, like so:
Error 20 The type or namespace name 'IContentMaker' could not be found (are you missing a using directive or an assembly reference?)
notge that I have inherited the class library namespace using the 'using' keyword just in case you are wondering. My code is like so:
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using TQO_Classes ; //importing the class library project
public partial class PageContentMgr : System.Web.UI.UserControl
{
private IContentMaker _data; //this line throws the error, it works fine on aspx pages
View 1 Replies
Feb 17, 2011
I have created a custom control as can be seen below. this custom control will be used by alot of web form. The question is how to override CheckAllData method in each webform, so i can write my own checking in each webform.
[Code]....
View 5 Replies
Aug 6, 2010
My web services have base web service method called IsGood()I want to make sure every methods in my web service call IsGood() in base web service automatically without add code in each web service method, can I do that?
View 2 Replies
Jan 12, 2011
auton=createsid(num)
INSERT INTO Store_Information (sid,store_name, Sales, Date)
SELECT store_name, Sales, Date
FROM Sales_Information
in the baove i need to add the SID which is a no obtained from incrmenated function, how do i add itautono will contain the incremnet value which i need to add to sid column
View 18 Replies
Mar 25, 2011
i have a dataTable, which contains a column which has 100 rows, now i want to add those rows in ArrayList, but not with the Add Method, because i have to use for loop for adding records one by one, so i want to prefer addrange method of arraylist, so it is possible to add records in arraylist from DataTable using AddRange.
Below is the code which i am using.
Dim adapGetImages As New SqlDataAdapter("select distinct FileName from Files where Filename<>'' and (RIGHT(FileName,3) = 'gif' or RIGHT(FileName,3) = 'jpg' or RIGHT(FileName,3) = 'bmp') order by FileName", connection)
Dim dtGetImages As New DataTable()
adapGetImages.Fill(dtGetImages)
ArrayList1.AddRange(dtGetImages.Rows[0][0].ToString())
The last line is where i am stuck. as if i run this it will just add single row, and if i say dtGetImages.Rows.ToString() then this will just Add System.DataRow in Arraylist and not its content.
View 2 Replies
Feb 3, 2011
When I used the (way #1) below I could retrieve search result from my DB
Way #1:
[Code]....
But When I use( way#2) "separating my code to Presentation layer and data access layer ( using SQL HELPER CLASS )"
Way # 2
Presentation layer: protected void btn_Search_Advance_Click(object sender, EventArgs e)
[Code]....
data access layer:
[Code]....
I keep getting this error: Procedure or function 'SP_Search' expects parameter '@SEARCHTYPE', which was not supplied.
View 6 Replies
Apr 3, 2011
I have a gridview which uses a stored procedure with session["UserName"] as a parameter to retrieve the records from the database.
Here is the code for that gridview Sqldatasource:
[code]....
lets say a particular user who has logged in doesn't have any records in that table on which this particular stored procedure is being executed. Then there won't be any records associated with gridview. So in this scenario: is there any method that gets executed or some exception is thrown, so that i can explicitly use that method/exception/property to display a message Label to the user like "No records to show !!"
View 3 Replies
Mar 15, 2011
What is the best way to create a Contract that will consume multiple database records? The database records will have 20 fields and maximun of 1000 rows.
View 1 Replies
Dec 19, 2010
How to simplify this, 2 method in class are identical. First class.
Public Class Gui
Inherits System.Web.UI.Page
Public Sub CreateStyleLink(ByVal StyleArray() As String)
Dim StrStyleLink As String
[Code]....
View 3 Replies
Jan 28, 2010
What is the best and most efficient way to set custom ASP.Net Calendar day properties from sql Database records? Each existing record has date column that corrosponds with calendar's date.
Can this be done without writing a custom server control?
View 5 Replies
Nov 24, 2010
I have a class file called ShoppingCartClass.cs. Inside ShoppingCartClass I have a method called CanadaPostShipping.
CanadaPostShipping get passed a lot of variables and then builds an xml, sends it to CanadaPost url and gets back an xml file with the shipping rates.
I would like to pass the xml back to my webpage so in my web page I can check that it has status ok and then extract the information I need.
My testing calling routine looks like this:
[Code]....
The start of my CanadaPostShipping routine looks like this
[Code]....
This is my current ending spot in CanadaPostShipping....where I am getting back the correct xml from CanadaPost
[Code]....
As you can see I am saving it to my thumbdrive.....
What changes would I have to make to my calling routine and the method in the class to return xml "mydoc"?
View 1 Replies
Feb 12, 2011
For instance if I'm inside the Page_Load method and I want to get query string data I just do this:
public partial class Product_Detail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
[code].....
View 4 Replies
Jul 23, 2010
I've moved a class in my project into a class Library in the same solution. I've added a reference in the web project to the class library.
How do I access the methods in the class library?
View 2 Replies
Aug 17, 2010
I am learning Asp.net web application. I have one doubt.
Is it possible to pass the DataTable from one Method to another in the same class?
View 4 Replies