我有一个IBankAccount接口,我将传递给ApplicationService。帐户对象(在ApplicationService项目中)所做的更改需要在数据库中保存。存储库使用IBankAccount接口接收更改。我怎样才能将这些数据保存到数据库中?这是使用LINQ to SQL实现的。 。通过接口编程保存数据
注:以下是从斯科特http://weblogs.asp.net/scottgu/archive/2007/06/29/linq-to-sql-part-3-querying-our-database.aspx 评论“到你的LINQ的接口添加到SQL数据模型类的LINQ to SQL类是局部类 - 这意味着你可以直接添加界面给他们。 “
public class LijosSimpleBankRepository : ILijosBankRepository
{
public System.Data.Linq.DataContext Context
{
get;
set;
}
public virtual void UpdateAccount(DomainInterfaces.IBankAccount iBankAcc)
{
DBML_Project.BankAccount bankAccount;
}
}
namespace DomainInterfaces
{
public interface IBankAccount
{
int BankAccountID { get; set; }
string AccountType { get; set; }
System.Nullable<System.DateTime> OpenedDate { get; set; }
string Status { get; set; }
System.Nullable<int> AccountOwnerID { get; set; }
}
}
namespace DBML_Project
{
public class FixedBankAccount : BankAccount
{
//Note: BankAccount already implemnts IBankAccount
}
public class SavingsBankAccount : BankAccount
{
//Note: BankAccount already implemnts IBankAccount
}
//The auto generated calss is made as abstract
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.BankAccount")]
[InheritanceMapping(Code = "Fixed", Type = typeof(FixedBankAccount), IsDefault = true)]
[InheritanceMapping(Code = "Savings", Type = typeof(SavingsBankAccount))]
public abstract partial class BankAccount : INotifyPropertyChanging, INotifyPropertyChanged, DomainInterfaces.IBankAccount
{
..
}
}
READING
How do you abstract out your persistence code when using LINQ to SQL?
LINQ to SQL - mapping exception when using abstract base classes
theNameOfYourDBContext.SaveChanges() – Boomer
@Boomer我只接收存储库方法中的一个接口。您的建议不起作用 – Lijo
如果您知道您的IBankAccount参数肯定是BankAccount类型的,您可以只投出对象...? –