I am creating small application where I have done with Business Class. Now, I want to create report.
Firstly, Here is my Property Class :
public class Property
{
public int PropertyId { get; set; }
public int OwnerId { get; set; }
//User is another Class
public User Owner { get; set; }
public int StaffUserId { get; set; }
public Staff StaffPerson { get; set; }
public string Address { get; set; }
public int NoGarage { get; set; }
public int NoRoom { get; set; }
public int NoToilet { get; set; }
public string PropertyType { get; set; }
public string PropertyStatus { get; set; }
public double SalePrice { get; set; }
public double RentPricePerMonth { get; set; }
public bool IsAvailable { get; set; }
...............
And Here is my User Class :
public class User
{
public int UserId { get; set; }
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Password { get; set; }
public string PhoneNo { get; set; }
public string Email { get; set; }
Now I want to create report using Property class and also want to show User class.
I am able to show objects of Property class but not able to show User Class.
How can I do this?
Currently I am generating report using this :
Property p = Property.GetPropertyByPropertyId(propertyId);
PropertyBindingSource.DataSource = p;
reportViewer1.RefreshReport();
1.implement the Serializable interface to "User" class
[Serializable]
public class User
{
2.If, in case you want to display the user name,
In the design of the report, the expression of the item set a
=Fields!Owner.Value.UserName
Related
I want to create a generic method in which I can take out my DataGridView data into my desired Class list:
following is the DataGridView:
enter image description here
following is my class:
public partial class Parent
{
public int Id { get; set; }
public string FatherName { get; set; }
public string FatherCNIC { get; set; }
public int FatherQualificationId { get; set; }
public int FatherJobId { get; set; }
public string MotherName { get; set; }
public string MotherCNIC { get; set; }
public int MotherQualificationId { get; set; }
public int MotherJobId { get; set; }
public bool IsActive { get; set; }
public bool IsDeleted { get; set; }
public System.DateTime CreatedOn { get; set; }
public int CreatedBy { get; set; }
public Nullable<int> LastUpdatedBy { get; set; }
public Nullable<System.DateTime> LastUpdatedOn { get; set; }
public string FatherEmail { get; set; }
public string MotherEmail { get; set; }
}
I don't know where to start from this logic but I tried to pass data grid view and class list object as generic object but unable to bind of loop through the properties of class.
I have to use this logic multiple times that's why I am trying to create a generic method.
I'm working with asp.net webforms and I'm a beginner with Entity Framework. I need to know how to make an update page and send data from page to a method (binding) without having to bind field by field and save changes.
Suppose I have this class :
public class Fiche
{
[Key]
public int Id { get; set; }
public string mrmme { get; set; }
public string nometprenom { get; set; }
public string adresse { get; set; }
public string ville { get; set; }
public string cp { get; set; }
public string tele { get; set; }
public string portable { get; set; }
public string datenaissance { get; set; }
public string email { get; set; }
public string situation { get; set; }
public string profession { get; set; }
#region // Santé & Prévoyance
public string typesp { get; set; }
public string nombresassures { get; set; }
public string regime { get; set; }
public string nbrenfants { get; set; }
public string mutuelleactuelle { get; set; }
public string tarifcontrat { get; set; }
public string niveaugaranties { get; set; }
public string mutuelle { get; set; }
#endregion
public string Createdbynom {
get {
return Data.Db.Users.Find(Createdby).nom;
}
}
public string Affectedtonom
{
get
{
return Data.Db.Users.Find(Affectedto).nom;
}
}
public ICollection<Contrat> Contrats { get; set; }
public ICollection<Commentaire> Commentaires { get; set; }
public string Createdby { get; set; }
[ForeignKey("Createdby")]
public ApplicationUser createuser { get; set; }
public string Affectedto { get; set; }
[ForeignKey("Affectedto")]
public ApplicationUser affetcteduser { get; set; }
}
I have lot of fields if I want to create a form to update this model. I need to create textbox for every field and when I click "submit" button, I need to get every value from every textbox and bind to model and call SaveChnages?
Is this the only way in webforms to update data a database?
Is there any way to binding data from my form to my update method?
I have got the following three tables (just an example)
public class User
{
public int id { get; set; }
public string name { get; set; }
public List<Code> Codes { get; set; }
}
public class Device
{
public int id { get; set; }
public string name { get; set; }
public List<Code> Codes { get; set; }
}
public class Code
{
public int id { get; set; }
public int entity_id { get; set; }
public string entity_type { get; set; }
public string code { get; set; }
}
Now a code can either belong to a User or a Device, which will be determined by the value of entity_type (i.e. 'user' or 'device'). How can this be achieved in Entity Framework ?
You could change your Code class to
public class Code
{
public int id { get; set; }
public User user { get; set; }
public Device device { get; set; }
public string code { get; set; }
}
This way one of those properties can be null.
Hope it helps.
The drawback is that you could have a code that have a user an a device
I have a c# class as below
public class CreateStudent
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public int Age { get; set; }
}
and I need another class with following properties
public class EditStudent
{
public string Name { get; set; }
public string Address { get; set; }
public int Age { get; set; }
public DateTime Date_of_Birth { get; set; }
}
I have repeated properties except that one field (Date_of_Birth) is added in the EditStudent Model.
Is there an option to reuse some of the properties from previous CreateStudent model
I am going to handle these data as Json objects in my front end angularjs based application
You could do this with a null-able property.
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public int Age { get; set; }
public DateTime? Date_of_Birth { get; set; }
}
This way you only have one Student model that can accommodate both use-cases.
you should be using inheritance feature here.
public class CreateStudent
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public int Age { get; set; }
}
public class EditStudent : CreateStudent
{
public DateTime Date_of_Birth { get; set; }
}
Lambda Query
I am working with with EF6 MVC5 and set up my listing model to include a virtual ICollection of images. I want to query the listings and include an image with each listing title in my view. I am having trouble writing the lambda query in the controller to send to my view.
Listing Class
public class Listing
{
public int Id { get; set; }
public ApplicationUser User;
[Required]
public string UserId { get; set; }
public Category Category { get; set; }
public int CategoryId { get; set; }public string Title { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Website { get; set; }
public string Phone { get; set; }
public string LocationAddress1 { get; set; }
public string LocationAddress2 { get; set; }
public string LocationCity { get; set; }
public string LocationState { get; set; }
public string LocationZip { get; set; }
public string LocationCountry { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
[DataType(DataType.MultilineText)]
public string Comments { get; set; }
public bool isLEO { get; set; }
public bool isProperty { get; set; }
public string Keywords { get; set; }
public bool isNoShowAddress { get; set; }
public bool isActive { get; set; }
public bool isApproved { get; set; }
public virtual ICollection<Image> Images { get; set; }
public virtual ICollection<Review> Reviews { get; set; }
Image Class
public class Image
{
public int Id { get; set; }
public Listing Listing { get; set; }
public int ListingId { get; set; }
public string ImagePath { get; set; }
public bool isPrimary { get; set; }
public DateTime DateAdded { get; set; }
public bool isHidden { get; set; }
}
When you have nested objects I believe you do something like this:
var listings = dbcontext.Listings.Include("Images").Where(...)
Where include tells EF to fetch nested objects.
It could also be something like this:
var listings = dbcontext.Listings.Include(c=>c.Images).Where(...)
You have to project your query to another type specifically designed for use inside Views (this is often referred to as ViewModel) or you can just project it into an anonymous type, the approach is similar.
The following code assumes you will use an anonymous type:
var listings = dbContext.Listings.Select(l => new {
Id = l.Id,
User = l.User,
//add every property you need to show inside your View
Image = l.Images.FirstOrDefault(i => i.isPrimary)
});