public class project
{
public int id { get; set; }
public string ProjectName { get; set; }
public string Description { get; set; }
public string Category { get; set; }
public int UserprojectId { get; set; }
public int? SponserId { get; set; }
public decimal Cost { get; set; }
public DateTime CreatedTime { get; set; }
public DateTime EstimateTime { get; set; }
}
public class projectDB : DbContext
{
public DbSet<project> projects { get; set; }
}
and this model
public class sponser
{
public int id { get; set; }
public string FirstName { get; set; }
public string lastName { get; set; }
public string CompanyName { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public DateTime DateRegister { get; set; }
public String CompanyPhone { get; set; }
public string CellPhone { get; set; }
public string Email { get; set; }
public bool EmailConfirmation { get; set; }
public string Country { get; set; }
public string City { get; set; }
public string PostalCode { get; set; }
public String Address { get; set; }
}
public class sponserDB : DbContext
{
public DbSet<sponser> sponsers { get; set; }
}
and in my web confige file
i add this this name
<add name="SponseringDB"
connectionString="Data Source=(localdb)\v11.0;Initial Catalog=sponseringDB;Integrated Security=True"
providerName="System.Data.SqlServerCe.4.0"
/>
When run this and create some Record for me it made two database first sponseringDb and second is projectDb I want to use one database.
Need suggestions on achieving this.
You've got two classes inherit by DbContext and that is the reason why 2 database are created, if you want to have just one databe ie: projectDB
change you projectDB class to
public class projectDB : DbContext
{
public projectDB () : base("projectDBConnectionString") //<- name of your connection string
{
}
public DbSet<project> projects { get; set; }
public DbSet<sponser> sponsers { get; set; }
}
and in your web config add connection string named 'projectDBConnectionString' ie:
<add name="projectDBConnectionString"
connectionString="Data Source=(localdb)\v11.0;Initial Catalog=sponseringDB;Integrated Security=True"
providerName="System.Data.SqlServerCe.4.0"
/>
and now your can rid off connection string 'SponseringDB' from web.config and delete class 'sponserDB'
Hope that will help
Related
I have asked question in a different post, but seems that was not the right question, so going to reword here:
I have three classes:
public class StateLog : BaseModel
{
public Guid StateLogId { get; set; }
public Guid LookupMasterId { get; set; }
public Guid EntityId { get; set; }
public string Discriminator { get; set; }
public bool IsActive { get; set; }
public virtual LookupMaster State { get; set; }
}
Second class:
public class ApplicationState : StateLog
{
[Column("EntityId")]
public Guid ApplicationId { get; set; }
}
There is another Class DocumentStates which inherits from StateLog.
Application:
public class Application : BaseModel
{
public Guid ApplicationId { get; set; }
public Guid UserId { get; set; }
public virtual User User { get; set; }
[Required]
public Guid ApplicationTypeId { get; set; }
public bool? AuthorizedToWork { get; set; } = false;
public string Token { get; set; }
public string ApplicationTitle { get; set; }
public string WorkStartDate { get; set; }
public Nullable<DateTime> SignedAt { get; set; } = DateTime.Now;
public bool? Signed { get; set; }
public string Notes { get; set; }
public virtual ICollection<ApplicationSelfDeclaration> ApplicationSelfDeclarations { get; set; }
public virtual ICollection<ApplicationState> ApplicationStates { get; set; }
public virtual ICollection<StateLog> StateLogs { get; set; }
}
I am trying to save statelogs for both application and documents in same table and based on Discriminator, fetch data.
E.g.
_context.Applications.include(a => a.ApplicationState)
This is not not working. ApplicationState should Alias EntityId column as ApplicationId. But it is not working.
Any idea what my options are at this point?
Thanks in advance.
DB relationship:
1ApplicationUser : n Tickets
1ApplicationUser: n Activities
1Tickets:n Activites
I would like to design above database using code first. However,there's error warning
"Column name 'ApplicationUserId' in table 'Tickets' is specified more
than once."
However, I checked there's only one ApplicationUserId in Table Ticket as shown in below class.
Would anyone please help how to fix it? Thanks.
The entity class are as following:
Ticket Class
public class Ticket
{
public int ID { get; set; }
public Ticket()
{ TicketCreateDate = DateTime.Now; }
public DateTime TicketCreateDate { get; set; }
public int TicketCreateBy { get; set; }
public DateTime TicketCloseDate { get; set; }
public int TicketCloseBy { get; set; }
public DateTime LastTicketUpdateDate { get; set; }
public int LastUpdateBy { get; set; }//Ticket Last Update by
public DateTime TicketAssignedDate { get; set; }
public int TicketAssignedTo { get; set; }
public string TicketType { get; set; }
public string Priority { get; set; }// Ticket priority
public string TicketStatus { get; set; }
public string TicketDescription { get; set; }
public int DeviceUserID { get; set; }
public string DeviceBrand { get; set; }
public string DeviceType { get; set; }
public virtual ICollection<Activity> Activities { get; set; }
public int ApplicationUserID { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
}
Acitivity Class
public class Activity
{
public int ID { get; set; }
public Activity()
{
CreatedTime = DateTime.Now;
}
public DateTime CreatedTime { get; set; }
public string ActivityDetails { get; set; }
public int ApplicationUserID { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
public int TicketId { get; set; }
public virtual Ticket Ticket { get; set; }
}
ApplicationUser Class
public class ApplicationUser : IdentityUser
{
public virtual ICollection<Ticket> Tickets { get; set; }
public virtual ICollection<Activity> Activities { get; set; }
}
I can't figure out what the problem is. I am using Entity Framework 6 to access an Oracle 12c Database. When I try to add a new row to the table I get the ORA-01400 error in my title. However, when I look at the values that I am attempting to add in the debugger they are not null.
protected void InsertButton_Click(object sender, EventArgs e)
{
AddNewPartner(GetFields());
}
public void AddNewPartner(FTP_GET_TESTING ftpPartner)
{
using (Entities myEntities = new Entities())
{
myEntities.FTP_GET_TESTING.Add(ftpPartner);
myEntities.SaveChanges();
}
}
Update
Here is the model(it is Data First):
public partial class FTP_GET_TESTING
{
public string FTP_LOOKUP_ID { get; set; }
public string FTP_HOST { get; set; }
public string USER_NAME { get; set; }
public string PASSWORD { get; set; }
public string ADAPTER { get; set; }
public string FTP_MODE { get; set; }
public string PICKUP_FOLDER { get; set; }
public string DESTINATION_FOLDER { get; set; }
public string DELIVERY_FILENAME { get; set; }
public string DESTINATION_BP { get; set; }
public string ARCHIVE_FOLDER { get; set; }
public string REMOTE_ARCHIVE_FILE_EXTENSION { get; set; }
public string REMOTE_ARCHIVE_DIRECTORY { get; set; }
public string REMOTE_FILE_DELETE { get; set; }
public string FTP_DOWN { get; set; }
public string FILTER { get; set; }
public string LISTSIZE_FLAG { get; set; }
public decimal LIST_MAX { get; set; }
public string CHECK_FILE_SIZE { get; set; }
public string PGP_DECRYPT { get; set; }
public string PGP_PASSPHRASE { get; set; }
public string CONNECTION_TYPE { get; set; }
public string REPRESENTATION_TYPE { get; set; }
public string FTPS_CACERTIFICATE_ID { get; set; }
public string FTPS_CIPHER_STRENGTH { get; set; }
public string PORT { get; set; }
public string FTPS_SSL { get; set; }
public string FTPS_SYSTEM_CERT_ID { get; set; }
public string SFTP_COMPRESSION { get; set; }
public string SFTP_KNOWNHOST_KEY_ID { get; set; }
public string SFTP_PREF_AUTH_METHOD { get; set; }
public string SFTP_PREFERRED_CIPHER { get; set; }
public string SFTP_PREFERRED_MAC { get; set; }
public string SFTP_USER_ID_KEY_ID { get; set; }
public string FMC_RELATIONSHIP_NAME { get; set; }
public string USER_FIELD1 { get; set; }
public string USER_FIELD2 { get; set; }
public string USER_FIELD3 { get; set; }
public string NOTES { get; set; }
public Nullable<System.DateTime> LAST_UPDATE { get; set; }
public string LAST_USER_UPDATE { get; set; }
public string PARTNER_NAME { get; set; }
public string MAILBOX_ID { get; set; }
public string REMEDY_QUEUE { get; set; }
public string SCHEDULE { get; set; }
public Nullable<decimal> ALERT_FREQUENCY { get; set; }
public string PRIORITY { get; set; }
public string CONTACT_NAME { get; set; }
public string CONTACT_EMAIL { get; set; }
public string CONTACT_PHONE { get; set; }
public string FTP_SEND_LOOKUP_ID { get; set; }
}
I verify the data added using the immediate window in the debugger.
myEntities.FTP_GET_TESTING.Add(ftpGet);
{GP_GENERIC_FTP_GET_TESTING}
ADAPTER: "FTP_Client_Adapter_Group"
ALERT_FREQUENCY: 120
ARCHIVE_FOLDER: ""
CHECK_FILE_SIZE: "NO"
CONNECTION_TYPE: "PASSIVE"
CONTACT_EMAIL: "Atest"
CONTACT_NAME: "Atest"
CONTACT_PHONE: "Atest"
DELIVERY_FILENAME: ""
DESTINATION_BP: ""
DESTINATION_FOLDER: ""
FILTER: ""
FMC_RELATIONSHIP_NAME: ""
FTPS_CACERTIFICATE_ID: ""
FTPS_CIPHER_STRENGTH: ""
FTPS_SSL: ""
FTPS_SYSTEM_CERT_ID: ""
FTP_DOWN: "N"
FTP_HOST: "Change"
FTP_LOOKUP_ID: "AnotherTest4"
FTP_MODE: "FTP"
FTP_SEND_LOOKUP_ID: ""
LAST_UPDATE: {12/28/2015 8:49:49 AM}
LAST_USER_UPDATE: "driver"
LISTSIZE_FLAG: "TRUE"
LIST_MAX: 520
MAILBOX_ID: ""
NOTES: "Atest"
PARTNER_NAME: "Atest"
PASSWORD: "Atest"
PGP_DECRYPT: "N"
PGP_PASSPHRASE: ""
PICKUP_FOLDER: ""
PORT: "21"
PRIORITY: "8x5"
REMEDY_QUEUE: "Atest"
REMOTE_ARCHIVE_DIRECTORY: ""
REMOTE_ARCHIVE_FILE_EXTENSION: ""
REMOTE_FILE_DELETE: "Y"
REPRESENTATION_TYPE: "BINARY"
SCHEDULE: "60MIN"
SFTP_COMPRESSION: ""
SFTP_KNOWNHOST_KEY_ID: ""
SFTP_PREFERRED_CIPHER: "blowfish-cbc"
SFTP_PREFERRED_MAC: ""
SFTP_PREF_AUTH_METHOD: ""
SFTP_USER_ID_KEY_ID: ""
USER_FIELD1: ""
USER_FIELD2: ""
USER_FIELD3: ""
USER_NAME: "Atest"
and I think this is the config info you wanted to see.
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
What else do I need to add here to help figure out the problem?
To fix this I did two things. First I deleted the model FTP_GET_TESTING and then I compared the primary key(FTP_LOOKUP_ID) in the testing table to the PK in the non testing table and there were some differences.
In design view of the table FTP_GET_TESTING my PK Constraint was named SYS_C0027857 I changed it to FTP_GET_TESTING_PK. I also changed the name of the index to match the constraint name FTP_GET_TESTING_PK. Then I added the table back into my model and it worked perfectly.
I am not sure if changing the PK name in constraints and indexes fixed the issue or if simply deleting and re-adding did the trick.
If anyone cares to add some input on this for future viewers, and so that I can understand what happened a little more I would appreciate it.
ASP .NET MVC4
Class #1:
public class F61BPROD
{
public int WPDOCO { get; set; }
public string WPDCTO { get; set; }
public string WPMCU { get; set; }
public string WPLOCN { get; set; }
public string WPDCT { get; set; }
public int WPTRDJ { get; set; }
public string WPKYPR { get; set; }
public string WPLITM { get; set; }
public decimal WPTRQT { get; set; }
public string WPKYFN { get; set; }
public string WPLOTN { get; set; }
public string WPLRP1 { get; set; }
public string WPLRP2 { get; set; }
public string WPLRP3 { get; set; }
public string WPLRP4 { get; set; }
public string WPLRP5 { get; set; }
public string WPLRP6 { get; set; }
public string WPLRP7 { get; set; }
public string WPLRP8 { get; set; }
public string WPLRP9 { get; set; }
public string WPLRP0 { get; set; }
public string WPFLAG { get; set; }
public string WPLOT1 { get; set; }
public string WPLOT2 { get; set; }
}
For one of the properties of Class #1 i need to fetch one of Class #2:
public class JDEItemBasic
{
public int itm { get; set; }
public string litm { get; set; }
public string dsc { get; set; }
public string dsce { get; set; }
public string ean14 { get; set; }
public string cc { get; set; }
public string uom1 { get; set; }
public string uom2 { get; set; }
public int uom1ea { get; set; }
public int bxuom1 { get; set; }
public int uom1gr { get; set; }
}
There is a DAL that gets the above classes. I need to combine these classes a new class that will have most of the properties of the above classes.
Should i create a third class and do the job in BLL?
or should i do it in UI using LINQ to Entities after i fetch them?
Should i create a third class and do the job in BLL?
or should i do it in UI using LINQ to Entities after i fetch them?
That would depend on where you need this class. If it is for displaying purposes then it should live in the UI. This class even has a name in this case: it's called a view model and is what your controller action could pass to the view after querying your DAL layer and projecting the various results to this view model.
i have a problem with my join in my asp.net .. i have two database tables.. named APPLICANT and Profile...they have the same fields.. meaning if the Last name in applicant is null the last name is already in profile table. I already connect my program to the applicant table.. but it have so many null fields that have to fetch from the profile data table.... sorry i'm new in asp.net ...
Here's my code in controller:
public View Result Index()
{
var applicants = (from a in db.APPLICANTs
select a).ToList();
return View(applicants);
}
heres my context:
public partial class APPLICANT
{
public int APPLICANT_ID { get; set; }
public Nullable<int> Profile_id { get; set; }
public string APPLICANT_LastName { get; set; }
public string APPLICANT_FirstName { get; set; }
public string APPLICANT_MiddleName { get; set; }
public string APPLICANT_Address { get; set; }
public string APPLICANT_City { get; set; }
public string APPLICANT_ZipCode { get; set; }
public string APPLICANT_Phone { get; set; }
public string APPLICANT_Email { get; set; }
}
public partial class Profile
{
public int PROFILE_ID { get; set; }
public string Applicant_LASTNAME { get; set; }
public string Applicant_FIRSTNAME { get; set; }
public string Applicant_MIDDLENAME { get; set; }
public string Applicant_EMAIL { get; set; }
public string Applicant_PHONE { get; set; }
public string Applicant_ADDRESS { get; set; }
public string Applicant_ZIPCODE { get; set; }
public string Applicant_CITY { get; set; }
}
thanks for those who can help my problem..