【发布时间】:2015-09-20 19:49:10
【问题描述】:
我有以下三个课程
Om_MembershipCharges 类
public class Om_MembershipCharges
{
[Key]
public Int32 MembershipChargesID { get; set; }
public Decimal Amount { get; set; }
public Int16 PerMonth { get; set; }
public Int16? CountryID { get; set; }
public Int16 MemebershipTypeID { get; set; }
public virtual Om_MembershipType MemebershipType { get; set; }
public virtual Om_Country Country { get; set; }
}
Om_MembershipType 类
public class Om_MembershipType
{
[Key]
public Int16 MemebershipTypeID { get; set; }
public String MemebershipType { get; set; }
public Boolean IsDefaultMembership { get; set; }
public virtual ICollection<Om_MembershipCharges> MembershipCharges { get; set; }
}
Om_Country 类
public class Om_Country
{
[Key]
public Int16 CountryID { get; set; }
public String CountryName { get; set; }
public Boolean IsActive { get; set; }
public Int16? CurrencyID { get; set; }
public Int32? MembershipChargesID { get; set; }
public virtual Om_Currency Currency { get; set; }
public Om_MembershipCharges MembershipCharges { get; set; }
}
下面是我在Om_MembershipType Class 中使用MembershipCharges Property 获取所有会员费用的方法。我正在使用Include 来获取收藏。
public async Task<KeyValuePair<String, Om_MembershipType>> ListByMType(String mType)
{
try
{
using (var membershipChargesContext = new DatabaseTables())
{
using (var transaction = new TransactionScope(
TransactionScopeOption.Required,
new TransactionOptions { IsolationLevel = IsolationLevel.ReadUncommitted },
TransactionScopeAsyncFlowOption.Enabled))
{
membershipChargesContext.Configuration.ProxyCreationEnabled = false;
var data = await membershipChargesContext
.tblMembershipType
.Where(i => i.MemebershipType == membershipType)
.Include(i => i.MembershipCharges)
.FirstOrDefaultAsync();
transaction.Complete();
return new KeyValuePair<String, Om_MembershipType>("", data);
}
}
}
catch (Exception ex)
{
var exception = ex.Message;
if (ex.InnerException != null)
exception = ex.InnerException.ToString();
return new KeyValuePair<String, Om_MembershipType>(exception, null);
}
}
有什么方法可以获取Membership Charges collection 中的 Country Instance 吗?
【问题讨论】:
标签: c# asp.net-mvc-4 c#-4.0 entity-framework-6 entity-framework-core