开发者

SubSonic, SimpleRepository and entity interfaces

Firstly, I want to apologize for my English, not my strongest side.

To the question. In my current project, I have interfaces to my entities so I can use Subsonic attributes at my head entites and I want to be able to seamlessly switch O/R mapper in the future. Anyway, I get an error when I try to use my interfaces and SimpleRepositorys classes like Single<>, All<> and so on. I know why I get the error message but I need help to find a way to get around it. Error message:

System.InvalidCastException: Unable to cast object of type 'SubSonic.DomainObjects.User' to type 'Core.DomainObjects.IUser'.

Code:

public IUser FindById(int id) {

var user = _repository.Single<User>(x => x.Id == id);

return (IUser)user;

}

As you can see I have tried to make User to IUser order to work when I want to add data, but without success. What can I do to make this work?

开发者_运维技巧

Thank you,

Timmie


I don't think subsonic is the problem in this situation. This code will work:

namespace Core.Objects
{
    public interface ICustomer
    {
        int CustomerID { get; set; }
        string Name { get; set; }
    }

}

Code for the actual class:

namespace Business.Entities
{
        public class Customer: Core.Objects.ICustomer
        {
            public int CustomerID { get; set; }

            [SubSonicStringLength(50)]
            public string Name { get; set; }
        }
}

And finally, the function to get the customer:

private static ICustomer CustomerByID(int id)
{
      var repos = new SimpleRepository("Test", SimpleRepositoryOptions.None);
      var customer = repos.Single<Customer>(c => c.CustomerID == id);

      return (ICustomer) customer;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜