Your repository should accept BankAccount
– not IBankAccount
because Linq-to-sql doesn’t know what is IBankAccount
and compiler doesn’t allow you to store it without casting it first to BankAccount
(that can obviously fail at runtime if IBankAccount
instance is not a BankAccount
).
Once you have BankAccount
you simply call:
Context.BankAccounts.Add(account);
Context.SubmitChanges();
Related Contents:
- Polymorphism: Is ORM entity a Domain Entity or Data Entity?
- Making Entity Class Closed for Changes
- Get all associate/composite objects inside an object (in Abstract way)
- Returning IEnumerable vs. IQueryable
- Difference Between Select and SelectMany
- EF codefirst : Should I initialize navigation properties?
- What is the syntax for an inner join in LINQ to SQL?
- LINQ – Left Join, Group By, and Count
- How can I conditionally apply a Linq operator?
- LINQ to SQL – Left Outer Join with multiple join conditions
- NHibernate QueryOver with Fetch resulting multiple sql queries and db hits
- To return IQueryable or not return IQueryable [closed]
- Understanding .AsEnumerable() in LINQ to SQL
- C# “internal” access modifier when doing unit testing
- TransactionScope vs Transaction in LINQ to SQL
- How to compare only Date without Time in DateTime types in Linq to SQL with Entity Framework?
- LINQ: combining join and group by
- LINQ Expression to return Property value?
- Compare nullable types in Linq to Sql
- LINQ to SQL: Multiple joins ON multiple Columns. Is this possible?
- Max or Default?
- Accessing properties through Generic type parameter
- Convert Linq Query Result to Dictionary
- Am I misunderstanding LINQ to SQL .AsEnumerable()?
- How do you perform a CROSS JOIN with LINQ to SQL?
- LINQ Where Ignore Accentuation and Case
- Updating an ObservableCollection in a separate thread
- Minimal and correct way to map one-to-many with NHibernate
- A dependent property in a ReferentialConstraint is mapped to a store-generated column
- How to make LINQ execute a (SQL) LIKE range search
- Refactoring code to avoid anti-pattern
- Identifying NHibernate proxy classes
- Using contains() in LINQ to SQL
- Should I abstract the validation framework from Domain layer?
- LINQ and pagination [duplicate]
- LINQ to SQL Where Clause Optional Criteria
- ‘CompanyName.Foo’ is a ‘namespace’ but is used like a ‘type’
- C# – Asserting two objects are equal in unit tests
- MVVM: Binding to Model while keeping Model in sync with a server version
- Multiple Aggregates / Repositories in one Transaction
- NHibernate How do I query against an IList property?
- How to implement batch fetching with Fluent NHibernate when working with Oracle?
- NHibernate – Many to Many Query using Junction/Joiner Table
- Custom Method in LINQ to SQL query
- How to create NHibernate HasManyToMany relation
- NUnit Test Run Order
- Get sum of two columns in one LINQ query
- Best way to update LINQ to SQL classes after database schema change
- Best way to save a ordered List to the Database while keeping the ordering
- Last and LastOrDefault not supported