This my custom class. I want this using class custom create complex type.
I am using C#, ASP.NET MVC 4.5 and SQL Server 2012
Thank you
SQL Server table name : CompanyModel
public class CompanyModel
{
public int CompanyID { get; set; }
public string SubDomain { get; set; }
public string CompanyName { get; set; }
public string WebSite { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
public string Address { get; set; }
}
I do not want it
IEnumerable<spGetCompanies_Result> spGetCompanies();
I want this.. it's possible ?
IEnumerable<CompanyModel> spGetCompanies();
Maybe I can add the class name here?
http://i.hizliresim.com/vQJkkr.png
This example could be the solution?
[Table(Name = "CompanyModel")]
public class CompanyModel
{
[Column()]
public int CompanyID { get; set; }
[Column()]
public string SubDomain { get; set; }
[Column()]
public string CompanyName { get; set; }
[Column()]
public string WebSite { get; set; }
[Column()]
public string Phone { get; set; }
[Column()]
public string Fax { get; set; }
[Column()]
public string Address { get; set; }
}
I assume you generated the method spGetCompanies when you imported it from the database. That's when the type spGetCompanies_Result
was generated. You can change the return type for this method and the mapping will automatically adjusted.
CompanyModel
If you don't have a type CompanyModel as an entity, you could create a new ComplexType with the required properties. Then you wouldn't need the type in your own code.
Now you should be able to call a method spGetCompanies
that returns IEnumerable<CompanyModel>
. At the same time you could change the name to GetCompanies
as the model should not reflect that you call a stored procedure.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.