?
Solved

C# asp.net: interface for a partial class...

Posted on 2009-07-06
16
Medium Priority
?
589 Views
Last Modified: 2013-12-17
I'm trying to set up and interface that defines certain fields for all tables.  I'm using a partial class to inherit the definitions from the interface but I keep getting an error  " CPMS_DAL.tbl_Account does not implement interface member IENTBaseEntity.CreateDate"..it does this for each definition in IENTBaseEntity.

Please Help!

Thanks.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
 
namespace CPMS_DAL.Framework
{
    public interface IENTBaseEntity
    {
        DateTime CreateDate { get; set; }
        int CreateByID  { get; set; }
        DateTime UpdateDate { get; set;}
        int UpdateByID { get; set; }
        Binary Version { get; set; }
    }
}
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CPMS_DAL.Framework;
 
namespace CPMS_DAL
{
    public partial class tbl_Accounts : IENTBaseEntity {}
}

Open in new window

0
Comment
Question by:Samantha1667
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
16 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 24789470
Your class tbl_Accounts must implement the interface properties.
So your class tbl_Accounts should have these properties like below:
 public DateTime CreateDate
    {
        get
        {
            throw new NotImplementedException();
        }
        set
        {
            throw new NotImplementedException();
        }
    }

  Same goes for other properties...
You are free to implement the code in get /set  as per your need
0
 

Author Comment

by:Samantha1667
ID: 24790064
I'm working from a book and they said that this should be generated everytime the partial class is generated won't this keep that from happening?
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24790161
Yes but then you will need another  partial class in the same assembly that implements the Interface
i.e.
public partial class tbl_Accounts : IENTBaseEntity {}

another class
public partial class tbl_Accounts
{  //that implements the IENTBaseEntity properties
}

Also the interface and be implemented over more than one partial class.
At compile time they are merged to form a whole class.

check this: http://msdn.microsoft.com/en-us/library/wa80x488(VS.80).aspx
0
Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

 

Author Comment

by:Samantha1667
ID: 24794941
okay, here is the whole code solution I'm using and still get the same error:


IENTBaseEntity.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
IENTBaseEntity.cs:

namespace CPMS_DAL.Framework
{
public interface IENTBaseEntity
{
DateTime CreateDate { get; set; }
int CreateByID { get; set; }
DateTime UpdateDate { get; set;}
int UpdateByID { get; set; }
Binary Version { get; set; }
}
}

CustomizedEntities.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CPMS_DAL.Framework;

namespace CPMS_DAL
{
public partial class tbl_Accounts : IENTBaseEntity {}
}

ENTBaseData.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CPMS_DAL.Framework
{
public abstract class ENTBaseData where T : IENTBaseEntity
{
public abstract List Select();

public abstract T Select(int id);

public abstract void Delete(CPMSDataContext db, int id);

public void Delete(string connectionString, int id)
{
using (CPMSDataContext db = new CPMSDataContext(connectionString))
{
Delete(db, id);
}
}
}
}

tbl_AccountsData.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CPMS_DAL.Framework
{
public class tbl_AccountsData : ENTBaseData
{
public override List Select()
{
using (CPMSDataContext db = new CPMSDataContext())
{
return db.sp_Accounts_SelectAll().ToList();
}
}

public override tbl_AccountsData Select(int id)
{
using (CPMSDataContext db = new CPMSDataContext())
{
return db.sp_Accounts_SelectSingle(id).SingleOrDefault();
}
}
}
}

0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24798391
I am not sure I am understanding you but let me try one more time.
Partial class allows you to split code across multiple classes....
e.g.
public partial class tbl_Accounts : IENTBaseEntity {
//All you properite implemented here
}

is equivalent to combination of all 3 classes below:

public partial class tbl_Accounts
{  //implement CreateDate { get; set; } and CreateByID { get; set; } properties
}
public partial class tbl_Accounts
{  //implement UpdateDate { get; set;} and UpdateByID { get; set; } properties
}
public partial class tbl_Accounts
{  //implement Version { get; set; } property
}

But in your code I see just:
public partial class tbl_Accounts : IENTBaseEntity {}
and no other partial class ...so ideally nobody is implementing the IENTBaseEntity.
Note: Try removing partial keyword ... and still you should get that error...why becuase you class is not implementing the interface

Thats what I understand and not sure if this is something missing in my knowledge about partial classes.

Simple example: http://weblogs.asp.net/gunnarpeipman/archive/2008/06/08/c-and-partial-classes.aspx
0
 

Author Comment

by:Samantha1667
ID: 24798654
I understand that partial class lets you split code. This is what I understand: "You can create another file and then create a partial class that is named the same as the entity class and have that inherit the correct interface.  That way, you can regenerate the entity class as offter as you want and not have to worry about cusomizing its code."  

That is why the solution has this piece :

CustomizedEntities.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CPMS_DAL.Framework;

namespace CPMS_DAL
{
public partial class tbl_Accounts : IENTBaseEntity {}
}
0
 

Author Comment

by:Samantha1667
ID: 24807502
Hi, I'm pretty new at this.  Sorry to be so definite but I'm trying to understand why I get this error, there is a big disconnect between the the example in the book and what you guys are saying.  I'm hoping to get some help to sort it all out.  I thank you for your time in this.

Thanks.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24807952
as I said it has nothing to do with partial class....if your class wants to use interface....it has to implement all properties / methods of that interface.
Now if you have partial class this implementation can be split across those partial classes.
In the example of your book...check if there is any other code that says 'partial class tbl_Accounts  "

One more example:
http://www.dotnetspider.com/forum/193095-partial-classes-using-c-asp-net.aspx

Which book are you referring to? Are you using the exact same code or you are trying to learn concepts from the book and implement in your own project?

Note: On this thread...the very first post i.e. your question.. there is "Request Attention" button in Red color. You can use that to request attention from other experts to get some more input.
0
 

Author Comment

by:Samantha1667
ID: 24808357
the book I'm using is the WROX programmer to programmer:ASP.NEt 3.5 Enterprise Application Development with Visual Studio 2008 I'm looking at chapter 2 solution.  I don't see any other partial class just methods to add for deleting and updating records.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 200 total points
ID: 24810008
If you are going to implement an interface, then you need to define events, methods, and properties that match the signatures in the interface definition:

    public interface IENTBaseEntity
    {
        DateTime CreateDate { get; set; }
        int CreateByID  { get; set; }
        DateTime UpdateDate { get; set;}
        int UpdateByID { get; set; }
        Binary Version { get; set; }
    }

Each class would need read/write properties that match the name and return types (implicit), or the return types (explicit):

Implicit example:

    public class MyClass : IENTBaseEntity
    {
        public DateTime CreateDate { get; set; }
        public int CreateByID { get; set; }
        public DateTime UpdateDate { get; set; }
        public int UpdateByID { get; set; }
        public Binary Version { get; set; }
    }

Explicit example:

    public class AnotherClass : IENTBaseEntity
    {
        DateTime IENTBaseEntity.CreateDate { get; set; }
        int IENTBaseEntity.CreateByID { get; set; }
        DateTime IENTBaseEntity.UpdateDate { get; set; }
        int IENTBaseEntity.UpdateByID { get; set; }
        Binary IENTBaseEntity.Version { get; set; }
    }
0
 

Author Comment

by:Samantha1667
ID: 24852862
I'm so sorry I didn't get back to anyone on this list I was caught up in a crisis here at work that set an impossible deadline.  please forgive me I will be more attentive next time.  I will try "learned one"'s suggestion and see what happens.  Thank you all for your help I really appreciate it.  Thanks.
0
 

Author Comment

by:Samantha1667
ID: 25136262
Hey I'm finally back on this project. i was looking at the solution and I don't see why that would work.  Why would I use an interface when I have to define it every where else.  The whole point of an interface is plug-and-play.

I think the error is coming from  the below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CPMS_DAL.Framework;

namespace CPMS_DAL
{
    public partial class tbl_Accounts : IENTBaseEntity { }
}

the error I get says:
'CPMS_DAL.tbl_Accounts' does not implement interface member 'CPMS_DAL.Framework.IENTBaseEntity.CreateDate'

I get this error for each defined in the interace.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question